Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pass from function use in all

Posted on 2004-10-07
10
Medium Priority
?
164 Views
Last Modified: 2010-04-05
I receive an object like:

function DoSomething (ABar: TgnMenuBar): Boolean;
begin
  blablabla
end;

I wish to use ABar into a different procedure:

procedure ButtonClick...
  ABar.Color:= clRed;
end;

How to do this? How to declar the ABar as to can use it outside my function?
0
Comment
Question by:ginsonic
[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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 12249761
Hi,

To use DoSomething you have to write code like:

var ABar: TgnMenuBar;
begin
  if DoSomething (ABar) then begin
    ...
end;

Put the var declaration in interface section of the unit and you will be able to use ABar variable in your forms code.

unit ...
interface
...
var ABar: TgnMenuBar;

implementation

procedure GetABar;
begin
  if DoSomething (ABar) then begin
    ...
end;

// in the same or another unit:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ABar.Color:= clRed;
end;

Regards, Geo
0
 
LVL 6

Assisted Solution

by:david_barker
david_barker earned 800 total points
ID: 12249772
Declare a variable of like
myMenyBar : TgnMenuBar;
in the private section of your form.

Make sure that DoSomething and ButtonClick are also declared in your form and defined as

function TForm1.DoSomething (ABar: TgnMenuBar): Boolean;
and
procedure TForm1.ButtonClick...

then do something like :

function DoSomething (ABar: TgnMenuBar): Boolean;
begin
  myMenyBar:=ABar;  // assign to my variable
  blablabla
end;

procedure ButtonClick...
  myMenuBar.Color:= clRed;  // changed to my variable
end;


0
 
LVL 9

Author Comment

by:ginsonic
ID: 12250326
Have a problem. I call my function with

0: if ShowEditor(TgnMenuBar(Component)) then
         Designer.Modified;

If add ShowEditor to TEditor , how you say, my compiler tell me that is unknown ( call from a different unit ).

On this moment my function is declared outside the TEditor class.
0
Industry Leaders: 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!

 
LVL 8

Expert Comment

by:BdLm
ID: 12250617
if you call functions from other units you have to add  them with the unit command. did you do this already?
0
 
LVL 17

Expert Comment

by:geobul
ID: 12250859
Add the unit name where ShowEditor is declared in USES clause of the unit where TEditor is declared.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12250998
done already , but don't recognize if is declared inside TEditor.
0
 
LVL 8

Expert Comment

by:BdLm
ID: 12251339
what ths exact compiler error message? can you post your unit teditor and the calling unit?
0
 

Expert Comment

by:joncmora
ID: 12255601
Put the variable declaration of your TgnMenuBar on the interface portion. Put it before the type declaration of TEditor. Have it look something like this

-------------------------
unit MyUnit;

interface

uses
  {Other units}, UnitContainingDeclarationOf_TgnMenuBar;

var
  MyBar: TgnMenuBar;

type
  TEditor = class(TCustomEditor)
    {Field declarations}
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


-------------------------
In your other units, use the unit in the interface section too.


unit MyOtherUnit;

interface

uses
  {Other units}, MyUnit, UnitContainingDeclarationOf_TgnMenuBar;
0
 
LVL 9

Author Comment

by:ginsonic
ID: 12256057
Done already :) But ... [Error] gnMenuBar.pas(1247): Undeclared identifier: 'ShowEditor'

Unit1 IS the TgnMenuBar declaration ( is my vcl :) ) and try to call my editor from Unit2.
0
 
LVL 17

Accepted Solution

by:
geobul earned 1200 total points
ID: 12256652
Hi,

Perhaps your ShowEditor function is not declared in the interface section of its unit:
-------
unit UnitContainingShowEditor;

interface

function ShowEditor(ABar: TgnMenuBar): Boolean;

implementation

function ShowEditor(ABar: TgnMenuBar): Boolean;
begin
  blablabla
end;

end.
----------
and then the unit where TgnMenuBar uses it:
-------
unit gnMenuBar;

interface

type TgnMenuBar ....

implementation

uses UnitContainingShowEditor;

....
procedure TgnMenuBar.AMethod;
begin
  ...
  if ShowEditor(TgnMenuBar(Component)) then
         Designer.Modified;
  ...
end;

end.
---------
Regards, Geo
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

688 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