lloydie-t
asked on
passing line number to a DLL
I have an app which reads strings from a file processes it in a DLL before showing the output. The problem I have is that the information is kept over to lines and I need the DLL to recognise which line it is reading from.
So the DLL is as follows
-------------------------- ---------- ---
library collexconv;
uses
ShareMem,
SysUtils,
Classes;
{$R *.res}
Function GrpNum (S: String): String; stdcall;
begin
Result := copy(S,1,1);
if Result = 'G' then begin
Result := copy(S,2,5);
Result := StringReplace(Result, ' ', '', [rfReplaceAll]); // is on line 1
end
else
Result := '';
end;
Function StartNum (S: String): String; stdcall;
begin
Result := copy(S,1,1);
if Result = 'A' then begin
Result := copy(S,2,5);
Result := StringReplace(Result, ' ', '', [rfReplaceAll]); // Is on line 2
end
else
Result := '';
end;
exports
GrpNum, StartNum;
end.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
and the app is
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --------
Uses
ShareMem;
Function GrpNum (S: String): String; stdcall; external 'collexconv.dll';
Function StartNum (S: String): String; stdcall; external 'collexconv.dll';
type
.........
........
.........
sl.LoadFromFile(CdrImportE dit.Text);
//loop though each line of text
for i := 0 to sl.count - 1 do
begin
group_no := GrpNum(sl[i]);
start_no := StartNum(sl[i]);
end;
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
I assume that in the app I can set an integer var, so that it is either line 0 or 1, but I then need to pass that info to the DLL so it can check it is reading the correct line.
So the DLL is as follows
--------------------------
library collexconv;
uses
ShareMem,
SysUtils,
Classes;
{$R *.res}
Function GrpNum (S: String): String; stdcall;
begin
Result := copy(S,1,1);
if Result = 'G' then begin
Result := copy(S,2,5);
Result := StringReplace(Result, ' ', '', [rfReplaceAll]); // is on line 1
end
else
Result := '';
end;
Function StartNum (S: String): String; stdcall;
begin
Result := copy(S,1,1);
if Result = 'A' then begin
Result := copy(S,2,5);
Result := StringReplace(Result, ' ', '', [rfReplaceAll]); // Is on line 2
end
else
Result := '';
end;
exports
GrpNum, StartNum;
end.
--------------------------
and the app is
--------------------------
Uses
ShareMem;
Function GrpNum (S: String): String; stdcall; external 'collexconv.dll';
Function StartNum (S: String): String; stdcall; external 'collexconv.dll';
type
.........
........
.........
sl.LoadFromFile(CdrImportE
//loop though each line of text
for i := 0 to sl.count - 1 do
begin
group_no := GrpNum(sl[i]);
start_no := StartNum(sl[i]);
end;
--------------------------
I assume that in the app I can set an integer var, so that it is either line 0 or 1, but I then need to pass that info to the DLL so it can check it is reading the correct line.
ASKER
Thanks for that Kate. I just need to inicate that the line number is either 0 or 1. Do you think the following would do that?
sl.LoadFromFile(CdrImportE dit.Text);
//loop though each line of text
for i := 0 to sl.count - 1 do
begin
{INSERTED BY KATE}
SetActualLine(Index);
{END OF INSERTION}
group_no := GrpNum(sl[i]);
start_no := StartNum(sl[i]);
{INSERTED BY LLOYD}
Inc (index)
if Index > 1 then
Index := 0;
{END OF INSERTION}
end;
sl.LoadFromFile(CdrImportE
//loop though each line of text
for i := 0 to sl.count - 1 do
begin
{INSERTED BY KATE}
SetActualLine(Index);
{END OF INSERTION}
group_no := GrpNum(sl[i]);
start_no := StartNum(sl[i]);
{INSERTED BY LLOYD}
Inc (index)
if Index > 1 then
Index := 0;
{END OF INSERTION}
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was already thinking along the same lines and had already changed part of my code. Thanks for the confirmation. I suppose you can probably tell I am new to delphi so any info about the use of DLL's is helpful.
here is another DLL example
https://www.experts-exchange.com/questions/20633440/Creating-DLL-for-Delphi.html
https://www.experts-exchange.com/questions/20633440/Creating-DLL-for-Delphi.html
also you can put very many parameters in a procedure or function in a DLL
procedure aProc(hWnd, aNum, aRef: Integer; aPnt: TPoint; aPchar: PChar; aRect: TRect);
you might look up "Parameters" and "Parameter semantics" and "Parameter passing" and "Calling conventions" in the delphi help, you can use the "var, const, and out " as types for a paraneter
procedure aProc(hWnd, aNum, aRef: Integer; aPnt: TPoint; aPchar: PChar; aRect: TRect);
you might look up "Parameters" and "Parameter semantics" and "Parameter passing" and "Calling conventions" in the delphi help, you can use the "var, const, and out " as types for a paraneter
what about simply put another function to dll, like this:
--------------------------
ibrary collexconv;
uses
ShareMem,
SysUtils,
Classes;
{$R *.res}
{INSERTED BY KATE}
var
ActualLine:Integer; // here the actual line is stored
Procedure SetActualLine (Line: Integer); stdcall;
begin
ActualLine:=Line;
end;
{END OF INSERTION}
Function GrpNum (S: String): String; stdcall;
begin
Result := copy(S,1,1);
if Result = 'G' then begin
Result := copy(S,2,5);
Result := StringReplace(Result, ' ', '', [rfReplaceAll]); // is on line 1
end
else
Result := '';
end;
Function StartNum (S: String): String; stdcall;
begin
Result := copy(S,1,1);
if Result = 'A' then begin
Result := copy(S,2,5);
Result := StringReplace(Result, ' ', '', [rfReplaceAll]); // Is on line 2
end
else
Result := '';
end;
exports
{INSERTED BY KATE}
SetActualLine,
{END OF INSERTION}
GrpNum, StartNum;
end.
--------------------------
and then in application call this function every single cycle:
--------------------------
Uses
ShareMem;
Function GrpNum (S: String): String; stdcall; external 'collexconv.dll';
Function StartNum (S: String): String; stdcall; external 'collexconv.dll';
type
.........
........
.........
sl.LoadFromFile(CdrImportE
//loop though each line of text
for i := 0 to sl.count - 1 do
begin
{INSERTED BY KATE}
SetActualLine(I);
{END OF INSERTION}
group_no := GrpNum(sl[i]);
start_no := StartNum(sl[i]);
end;
--------------------------
than you'll have ActualLine variable available in GrpNum and StartNum functions..
regards,
Kate