Solved

Help with functions

Posted on 1998-08-05
2
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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