IT79637
asked on
How to call a function in another unit?
Hi Experts,
I have two programs.
1. Unit1.pas is the main program.
2. search.pas contains functions that I want to call from the main program (Unit1.pas).
Below is a function from search.pas. The function call passes two strings to the function and returns an integer;
How would I code the call from the main program?
Thanks
I have two programs.
1. Unit1.pas is the main program.
2. search.pas contains functions that I want to call from the main program (Unit1.pas).
Below is a function from search.pas. The function call passes two strings to the function and returns an integer;
How would I code the call from the main program?
Thanks
Function from search.pas
-------------------------------
function PosInFile(Str, FileName: string): integer;
function NextChar: char;
begin
if BufPtr >= BufEnd then
begin
BlockRead(F, Buffer, MAXFILESIZE, BufEnd);
//ShowMessage('Char Read: '+IntToStr(BufEnd));
BufPtr := 0;
Application.ProcessMessages;
end;
Result := Buffer[BufPtr];
Inc(BufPtr);
end;
begin
Result := -1;
AssignFile(F, FileName);
Reset(F, 1);
BufPtr := 0;
BufEnd := 0;
Index := 0;
Increment := 1;
repeat
c := NextChar;
if c = Str[Increment] then
Inc(Increment)
else
begin
Inc(Index, Increment);
Increment := 1;
end;
if Increment = (Length(Str) + 1) then
begin
Result := Index;
break;
end;
until BufEnd = 0;
end;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OMY!!! So easy. Sorry I asked.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Up points to give credit due to all responders. Gave few extra points to tankergoblin because he was very kind in supplying a code sample. If anyone objects, please contact me.
Thanks to all.
Thanks to all.
dear bokist
i tried your way, but I got the following error
"This form of method call only allowed for class methods"
what should I do, I have a function "SendEmail" that will be used in all my units.pas and I want to write that function one time and call it from all the units
thank you
i tried your way, but I got the following error
"This form of method call only allowed for class methods"
what should I do, I have a function "SendEmail" that will be used in all my units.pas and I want to write that function one time and call it from all the units
thank you
@Amanda77,
For openers, start your own question. ;-)
Do so and I will supply an answer. ;-)
For openers, start your own question. ;-)
Do so and I will supply an answer. ;-)
ASKER
Below in the code section is procedure FindOCRString(); which is in the main program, Unti1. Below that is the entire program Functions;
This is how I make the function call from Unit1 (main program): posBegin := PosInFile(Str, FileName);
It throws compile error: Undeclared Identifier: "PosInFile".
Spelling seems to be correct.
I don't understand why?
Thanks.
Open in new window