Solved

A String Thing

Posted on 1998-12-18
2
152 Views
Last Modified: 2010-04-04
I am still in the early learning stages of Delphi(4) and have been experimenting with using a Common Unit(no form) that other units(with forms) can feed from. I'm trying to set something up where a Label Caption is set within the Common Unit and under certain conditions will show in designated labels on other forms. Any help? This is what I have so far:

{this is Unit2, my common unit}
procedure TryOut(Trial: boolean; TheLabel: TLabel; Cap: string);
begin
TheLabel.Caption := Cap;
if Trial = True then
Cap := 'True' else
Cap := 'False';
end;

{This is one of my Units(with Form)}
procedure TForm1.FormCreate(Sender: TObject);
begin
TryOut(True, Label1, Cap);
end;

If TryOut is set to True I want Label1.Caption as 'True'. On FormCreate Cap shows as an 'Undeclared Identifier'. How can I overcome this, bearing in mind I want the caption to come from the Common Unit.

PS Sorry for low points but almost bankrupt.
0
Comment
Question by:xpher
2 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 20 total points
ID: 1351842
You have described two independant things you want to do:

1. Place a caption in a label given that the caption is defined in some other unit.
2. Place a caption of 'true' or 'false' in a label given an appropriate flag.


For option 1 rewrite you code like this:

Unit Common;

const
  TheCaption = 'The caption';

end.

{this is Unit2, my common unit}
    procedure TryOut(TheLabel: TLabel);
    begin
    TheLabel.Caption := TheCaption;
    end;

    {This is one of my Units(with Form)}
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    TryOut(Label1);
    end;

For option 2 rewrite you code like this:

{this is Unit2, my common unit}
    procedure TryOut(Trial: boolean; TheLabel: TLabel);
    begin
    if Trial = True then
    TheLabel.Caption:= 'True' else
    TheLabel.Caption:= 'False';
    end;

    {This is one of my Units(with Form)}
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    TryOut(True, Label1);
    end;

If i have missed something here perhaps could could give me some more details of exactly what you want to do.

Cheers,

Raymond.
0
 
LVL 1

Author Comment

by:xpher
ID: 1351843
Thanks for prompt and excellent reply.
Works great, I used option 2.

Cheers
Chris :))
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

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…
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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