Solved

Help with functions

Posted on 1998-08-05
2
184 Views
Last Modified: 2010-04-04
I must be missing something simple. I add the the following function to unit1.pas:

function CheckPath(s: String): String;
begin
if (AnsiLastChar(s) = '\') then
CheckPath := Copy(s,1,Length(s) - 1)
Else
CheckPath := s;
end;

when i try to do s := CheckPath(DirectoryListBox1.Directory) in a procedure I get:

[Error] Unit1.pas(49): Undeclared identifier: 'CheckPath'

What am I missing?
0
Comment
Question by:LostOne
2 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 50 total points
ID: 1359919
Lets say the unit contain the checkpath function is called UnitZ.

There are few possiblities:
1. If you are calling the function from other unit (say unit1), you have to: [a] add the word unitZ in the uses clause of unit1 [b] declare the checkpath function in the Interface Section of unitZ.
2. If you just want to call the checkPath function within unitZ only, then you do not need to declare it in the interface section. However, the code for this function must come before you called it. ie

implementation

function CheckPath(s: String): String;
begin
  ...
end;

procedure Tform1.ABC;
var s: string;
begin
  .....
  s := CheckPath(DirectoryListBox1.Directory)
end;

.


BUT NOT

implementation

procedure Tform1.ABC;
var s: string;
begin
  .....
  s := CheckPath(DirectoryListBox1.Directory)
end;

function CheckPath(s: String): String;
begin
  ...
end;

.
0
 

Author Comment

by:LostOne
ID: 1359920
Thanks, the function came after the procedure I was trying to use it in. Doesn't make a difference is VB so I didn't even think aobut that.

Thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 89
Working with hours 3 58
How to debug For loops? 3 49
Delphi Yen format 3 35
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question