Solved

Help with functions

Posted on 1998-08-05
2
181 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now