Recent

Author Topic: learning my way through here  (Read 5224 times)

LearningTheRopes

  • Guest
learning my way through here
« on: December 30, 2004, 08:21:37 am »
Hello,

First time posting here, if this is the wrong place for it, then you have deepest apology.   :oops:

I have checked the archives for the past year and couldn't find what I was looking for.   :cry:

Please examine the following code, more information at end:

-----------------------------------------
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Menus,
  Unit2, StdCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    StaticText1: TStaticText;
    procedure MenuItem2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  MsgText: String;

implementation

{ TForm1 }

procedure TForm1.MenuItem3Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.MenuItem2Click(Sender: TObject);
begin
  Form2.Show();
  StaticText1.Caption := MsgText;
end;

initialization
  {$I unit1.lrs}

end.
-----------------------------------------

unit Unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Form2Hide(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form2: TForm2;
  MsgText : String; cvar; external;
 
implementation

{ TForm2 }

procedure TForm2.Button1Click(Sender: TObject);
begin
  Form2Hide(Sender);
  MsgText := 'Hello, all you young turkeys out there.';
end;

procedure TForm2.Form2Hide(Sender: TObject);
begin
  Form2.Hide();
  exit;
end;

initialization
  {$I unit2.lrs}

end.
-----------------------------------------

In procedure TForm2.Button1Click(Sender: TObject); , if I was programming in Visual Basic 3 (oldie)   8)   I could have written:

Form1.StaticText1.Caption := 'Hello, all you young turkeys out there.';

Why can't I do this here?

So I tried to do a 'global' varible that gets passed back so that Form1 can use it.

In the second form, the 'so called' external varible MsgText is an
'Undefined Reference' -- that is the message I keep getting, along with
'error while linking'.

So, how can I create a external varible that can be used in ALL units, and
how can I 'send' back more than one result, that is, two or more varibles
passed back to the calling routine.

I am trying to learn this stuff, haven't program in pascal since the early
to middle '80s.  Wish there were better docs for this stuff.  :roll:

I am 'trying' to translate a c/cpp program into pascal (I'll need all the
luck in the world - it seems.....)      :lol:

Many thanks --- James

Lightning

  • Sr. Member
  • ****
  • Posts: 422
learning my way through here
« Reply #1 on: December 30, 2004, 10:43:25 pm »
Get some Delphi books, go to the Lazarus-CCR website, you'll find tons of docs.
For your problem the code should be:
Code: [Select]

implementation

  uses Unit1;


You must add the unit wich contains your first form to your uses clause of the other unit wich sets the properties to the first form, to avoid recursive usage you must add it after the implementation part wich is not global , Pascal didn't change that much, it only added stuff and became more flexible.
The future must be... Fast and OpenSource so...
Think Open and Lightning Fast!

Anonymous

  • Guest
learning my way through here
« Reply #2 on: December 31, 2004, 09:00:58 am »
Thanks for the tip, I will be adding that in and try it in a day or two.

James

 

TinyPortal © 2005-2018