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
Solved

Help with functions

Posted on 1998-08-05
2
185 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

861 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