ginsonic
asked on
Pass from function use in all
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?
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Have a problem. I call my function with
0: if ShowEditor(TgnMenuBar(Comp onent)) 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: if ShowEditor(TgnMenuBar(Comp
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.
if you call functions from other units you have to add them with the unit command. did you do this already?
Add the unit name where ShowEditor is declared in USES clause of the unit where TEditor is declared.
ASKER
done already , but don't recognize if is declared inside TEditor.
what ths exact compiler error message? can you post your unit teditor and the calling unit?
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}, UnitContainingDeclarationO f_TgnMenuB ar;
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, UnitContainingDeclarationO f_TgnMenuB ar;
-------------------------
unit MyUnit;
interface
uses
{Other units}, UnitContainingDeclarationO
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, UnitContainingDeclarationO
ASKER
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.
Unit1 IS the TgnMenuBar declaration ( is my vcl :) ) and try to call my editor from Unit2.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
begin
ABar.Color:= clRed;
end;
Regards, Geo