Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to make a function global.


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jan 28, 2015 10:13 AM Last Post By: Remy Lebeau (Te...
Stev Warby

Posts: 50
Registered: 10/19/14
How to make a function global.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2015 9:41 AM
I have a function :

function DownloadIMG(const URL : String; var Image : TImage): Boolean;
var HTTP : TIdHttp;
Stream : TStream;
begin
Result := False;
HTTP := TIdHttp.Create(nil);
try
Stream := TMemoryStream.Create;
try
HTTP.Get(URL, Stream);
Stream.Position := 0;
Image.BitMap := TBitMap.Create(0, 0);
Image.BitMap.LoadFromStream(Stream);
Result := True;
finally
Stream.Free
end
finally
HTTP.Free
end;
end;

I now need to call this from another form (dataControls).

Thanks...
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How to make a function global.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2015 10:10 AM   in response to: Stev Warby in response to: Stev Warby
Stev Warby wrote:

I have a function :

function DownloadIMG(const URL : String; var Image : TImage): Boolean;
var HTTP : TIdHttp;
Stream : TStream;
begin
Result := False;
HTTP := TIdHttp.Create(nil);
try
Stream := TMemoryStream.Create;
try
HTTP.Get(URL, Stream);
Stream.Position := 0;
Image.BitMap := TBitMap.Create(0, 0);
Image.BitMap.LoadFromStream(Stream);
Result := True;
finally
Stream.Free
end
finally
HTTP.Free
end;
end;

I now need to call this from another form (dataControls).

Thanks...

Create a new unit, save it under an appropriate name, e.g.
GlobalroutinesU.pas, copy the function to the unit's implementation
section, and then copy just the function declaration to the unit's
interface section.

You will need to manually add the unit declaring TImage (Vcl.ExtCtrls
in a VCL project) to the Uses clause in the interface section, and
system.classes, vcl.graphics, IdHTTP to the Uses clause in the
implementation section. The IDE does not do this for you in this case.

The add the new unit to the Uses clause of the other units where you
need access to this function.

--
Peter Below (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to make a function global.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 28, 2015 10:13 AM   in response to: Stev Warby in response to: Stev Warby
Stev wrote:

I have a function :
<snip>
I now need to call this from another form (dataControls).

Make sure the function is declared in its unit's 'interface' section, and
then include the function's unit in the Form's 'uses' clause.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02