 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
dave Guest
|
Posted: Fri Oct 24, 2003 3:52 pm Post subject: Need help with an event....Please |
|
|
I have written an event called OnFieldFound(Sender : Tobject; FieldData :
string; FieldNum : integer);
I want the user to be able to change the fielddata string.(for special
handling of certain strings)
So in the IDE i set up code in my OnFieldFound event of my component that
says:
procedure TForm1.HL7Converter1FieldFound(Sender: TObject;
FieldData: String; FieldNum: Integer);
begin
if FieldNum = 7 then begin
FieldData := 'Test';
end;
end;
But when i look at my output file, the data was not changed at all. What do
i need to do to make changing the fielddata possible? My code is as follows:
unit HL7Converter;
{$R HL7CONVERTER.dcr}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
THL7FieldFoundEvent = procedure (Sender : TObject;FieldData :
string;FieldNum : integer) of object;
THL7Converter = class(TComponent)
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
private
FSegmentID : String;
FFieldNumbers : TStringList;
FHL7Filename : string;
FSaveFileName : string;
FOutputType : string;
FOutputDelim : string;
FUseHL7 : boolean;
FAllSegments : boolean;
FLineCount : Integer;
FHeaders : TStringList;
FUseHeaders : boolean;
FOutputToFile : boolean;
procedure SetLineCount(Value : integer);
procedure SetSegmentID(Value: string);
procedure SetSaveFileName(Value : string);
Procedure SetHL7Filename(value : string);
procedure SetOutputType(Value : string);
procedure SetOutputDelim(Value : string);
procedure SetUseHL7(Value : Boolean);
procedure SetAllSegments(Value : Boolean);
procedure SetFieldNumbers(Value : TStringList);
procedure SetHeaders(Value : TStringList);
Procedure ExecuteHL7Format;
procedure ExecuteCustomFormat;
procedure SetUseHeaders(Value : boolean);
procedure SetOutputToFile(Value : boolean);
protected
property LineCount :integer read FLineCount write SetLineCount;
function DoFieldFound(Sender: TObject; FieldData : string; FieldNum :
integer): string;
public
FOnFieldFound : THL7FieldFoundEvent;
Procedure ExecuteConversion;
published
property SegmentID : string read FSegmentID write SetSegmentID;
property SaveFileName : string read FSaveFileName write SetSaveFileName;
property HL7Filename : string read FHL7Filename write SetHL7Filename;
property OutputType : string read FOutputType write SetOutputType;
property OutputDelimiter : string read FOutputDelim write
SetOutputDelim;
property UseHL7Format : Boolean read FUseHL7 write SetUseHL7 default
False;
property AllSegments : Boolean read FAllSegments write SetAllSegments
default false;
property FieldNumbers : TStringList read FFieldNumbers write
SetFieldNumbers;
property Headers : TStringList read FHeaders write SetHeaders;
property UseHeaders : boolean read FUseHeaders write SetUseHeaders;
property OnFieldFound : THL7FieldFoundEvent read FOnFieldFound write
FOnFieldFound;
property OutputToFile : boolean read FOutputToFile write
SetOutputToFile;
end;
//function DoFieldFound( const Sender: TObject;var FieldFound :
THL7FieldFoundEvent): byte;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DLB Components', [THL7Converter]);
end;
{ THL7Converter }
constructor THL7Converter.Create(AOwner: TComponent);
begin
inherited;
FFieldNumbers := TStringList.Create;
FFieldNumbers.Sorted := false;
FHeaders := TStringList.Create;
FHeaders.Sorted := false;
LineCount := 0;
end;
destructor THL7Converter.Destroy;
begin
inherited;
FFieldNumbers.Destroy;
FHeaders.Destroy;
end;
function THL7Converter.DoFieldFound(Sender: TObject;
FieldData: string; FieldNum : integer): string;
begin
OnFieldFound(self, FieldData, FieldNum);
end;
procedure THL7Converter.ExecuteConversion;
var
FFileIn, FFileOut : TextFile;
strLine : AnsiString;
begin
//Prepare files
//input file
AssignFile(FFileIn,HL7Filename);
Reset(FFileIn);
// loop through input file to determine line count for progress event
// then reset the file for processing
while not eof(FFileIn) do begin
Readln(FFileIn, strLine);
LineCount := LineCount + 1;
end;
CloseFile(FFileIn);
if UseHL7Format then begin
ExecuteHL7Format;
end else begin
ExecuteCustomFormat;
end;
end;
procedure THL7Converter.ExecuteCustomFormat;
var
FFileIn, FFileOut : TextFile;
strLine, OutLine, strToWrite, HeaderLine, tempLine, TestChar : AnsiString;
LineCount, ii, FieldToGet, CountSection, PipePos, aa : Integer;
SectionNeeded : boolean;
begin
//Prepare files
//input file
AssignFile(FFileIn,HL7Filename);
Reset(FFileIn);
//output file
if OutputToFile then begin
AssignFile(FFileOut, SaveFileName);
Rewrite(FFileOut);
end;
if UseHeaders then begin
if Headers.Count < 1 then begin
end else begin
for ii := 0 to Headers.Count - 1 do begin
if ii = 0 then begin
HeaderLine := HeaderLine + Headers.Strings[ii];
end else begin
HeaderLine := HeaderLine + OutputDelimiter + Headers.Strings[ii];
end;
end;
if OutputToFile then begin
Writeln(FFileOut, HeaderLine);
end;
end;
end;
while not eof(FFileIn) do begin
Readln(FFileIn, strLine);
strToWrite := '';
CountSection := 0;
if copy(strLine, 1,3) = SegmentID then begin
strLine := copy(strLine, 5, length(strLine));
while pos('|', strLine) <> 0 do begin
PipePos := pos('|',strLine);
CountSection := CountSection + 1;
SectionNeeded := false;
for aa := 0 to FieldNumbers.Count - 1 do begin
if CountSection = strtoint(FieldNumbers.Strings[aa]) then begin
SectionNeeded := true;
end;
end;
if SectionNeeded then begin
OutLine := copy(strLine, 1, PipePos - 1);
if CountSection = 7 then begin
OutLine := copy(OutLine,1, ;
OutLine := copy(OutLine, 5,2) + '/' + copy(OutLine, 7,2) + '/' +
copy(OutLine,1,4);
if length(OutLine) < 4 then begin
OutLine := '';
end;
end;
if CountSection = 5 then begin
templine := OutLine;
Outline := '';
while length(tempLine) > 0 do begin
TestChar := templine[1];
if TestChar <> '^' then begin
Outline := OutLine + TestChar;
end else begin
OutLine := OutLine + ' ';
end;
if length(tempLine) > 1 then begin
tempLine := copy(tempLine, 2, length(tempLine));
end else begin
templine := '';
end;
end;
end;
//DoFieldFound(self, Outline, CountSection);
OnFieldFound(self, OutLine,CountSection);
if strToWrite = '' then begin
if outline <> '' then begin
strToWrite := OutLine;
end else begin
strToWrite := OutLine + OutputDelimiter;
end;
end else begin
strToWrite := strToWrite + OutLine + OutputDelimiter;
end;
end;
strLine := copy(strLine, PipePos + 1, length(strLine));
end;
strToWrite := copy(strToWrite, 1, length(strToWrite) - 1);
if OutputToFile then begin
Writeln(FFileOut, strToWrite);
end;
end;
end;
// cleanup files upon completion
CloseFile(FFileIn);
if OutputToFile then begin
Flush(FFileOut);
CloseFile(FFileOut);
end;
end;
procedure THL7Converter.ExecuteHL7Format;
var
FFileIn, FFileOut : TextFile;
strLine : AnsiString;
LineCount : Integer;
begin
//Prepare files
//input file
AssignFile(FFileIn,HL7Filename);
Reset(FFileIn);
//output file
AssignFile(FFileOut, SaveFileName);
Rewrite(FFileOut);
while not eof(FFileIn) do begin
Readln(FFileIn, strLine);
end;
// cleanup files upon completion
CloseFile(FFileIn);
Flush(FFileOut);
CloseFile(FFileOut);
end;
procedure THL7Converter.SetAllSegments(Value: Boolean);
begin
FAllSegments := Value;
end;
procedure THL7Converter.SetFieldNumbers(Value: TStringList);
begin
if Value <> nil then begin
FFieldNumbers.Assign(Value);
end;
end;
procedure THL7Converter.SetHeaders(Value: TStringList);
begin
if Value <> nil then begin
FHeaders.Assign(Value);
end;
end;
procedure THL7Converter.SetHL7Filename(value: string);
var
MyOpenDLG :TOpenDialog;
begin
if value = '' then begin
MyOpenDLG := TOpenDialog.Create(self);
MyOpenDLG.Filter := 'HL7 Files (*.hl7)|*.hl7';
if MyOpenDLG.Execute then begin
value := MyOpenDLG.FileName;
FHL7Filename := value;
end;
end else begin
FHL7Filename := value;
end;
end;
procedure THL7Converter.SetLineCount(Value: integer);
begin
FLineCount := Value;
end;
procedure THL7Converter.SetOutputDelim(Value: string);
begin
FOutputDelim := Value;
end;
procedure THL7Converter.SetOutputToFile(Value: boolean);
begin
FOutputToFile := Value;
end;
procedure THL7Converter.SetOutputType(Value: string);
begin
FOutputType := Value;
end;
procedure THL7Converter.SetSaveFileName(Value: string);
var
MyOpenDLG : TSaveDialog;
begin
if Value = '' then begin
MyOpenDLG := TSaveDialog.Create(self);
MyOpenDLG.DefaultExt := 'csv';
MyOpenDLG.Filter := 'CSV File (*.csv)|*.csv|Delimited Text File
(*.txt)|*.txt';
if MyOpenDLG.Execute then begin
value := MyOpenDLG.FileName;
FSaveFileName := value;
end;
end else begin
FSaveFileName := Value;
end;
end;
procedure THL7Converter.SetSegmentID(Value: string);
begin
FSegmentID := Value;
end;
procedure THL7Converter.SetUseHeaders(Value: boolean);
begin
FUseHeaders := Value;
end;
procedure THL7Converter.SetUseHL7(Value: Boolean);
begin
FUseHL7 := Value;
end;
{function DoFieldFound( const Sender: TObject;var FieldFound :
THL7FieldFoundEvent): byte;
var
Percent : Byte;
begin
if not Assigned(FieldFound) then
begin
Result := 0;
Exit;
end;
end;}
end.
Thanks in advance,
Dave
|
|
| Back to top |
|
 |
Marcel Bestebroer Guest
|
Posted: Fri Oct 24, 2003 4:15 pm Post subject: Re: Need help with an event....Please |
|
|
Hello, dave!
You wrote on Fri, 24 Oct 2003 10:52:09 -0500:
d> I want the user to be able to change the fielddata string.(for special
d> handling of certain strings)
[snip]
d> But when i look at my output file, the data was not changed at all. What
d> do i need to do to make changing the fielddata possible? My code is as
d> follows:
change:
d> THL7FieldFoundEvent = procedure (Sender : TObject;FieldData :
d> string;FieldNum : integer) of object;
into:
THL7FieldFoundEvent = procedure (Sender : TObject; var FieldData :
string;FieldNum : integer) of object;
--
Marcel Bestebroer (Team JEDI) http://delphi-jedi.org
Project JEDI Help coordinator
JVCL Help team coordinator
To mail me, remove the obvious from my mail address
|
|
| Back to top |
|
 |
dave Guest
|
Posted: Fri Oct 24, 2003 6:18 pm Post subject: Re: Need help with an event....Please |
|
|
Marcel, You Da Man!!
Thank you, something so simple gave me such a headache :)
Really appreciate the help.
Dave
"Marcel Bestebroer" <marcelb.theobvious (AT) zeelandnet (DOT) nl> wrote
| Quote: | Hello, dave!
You wrote on Fri, 24 Oct 2003 10:52:09 -0500:
d> I want the user to be able to change the fielddata string.(for special
d> handling of certain strings)
[snip]
d> But when i look at my output file, the data was not changed at all.
What
d> do i need to do to make changing the fielddata possible? My code is as
d> follows:
change:
d> THL7FieldFoundEvent = procedure (Sender : TObject;FieldData :
d> string;FieldNum : integer) of object;
into:
THL7FieldFoundEvent = procedure (Sender : TObject; var FieldData :
string;FieldNum : integer) of object;
--
Marcel Bestebroer (Team JEDI) http://delphi-jedi.org
Project JEDI Help coordinator
JVCL Help team coordinator
To mail me, remove the obvious from my mail address
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|