Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Turbo Delphi GUI Tutorials

pascal

  • Please log in to reply
16 replies to this topic

#13 HelpMePlz

HelpMePlz

    CC Newcomer

  • Member
  • PipPip
  • 20 posts

Posted 09 April 2012 - 12:45 PM

So I have a Unit (at least I think I do :P) called AllVariables where I have declared my global variables. I then went through and in the Uses section of each form put in AllVariables. In one form I use one of these variables, Username. Now in this form I have stated

Username := 'HelpMePLz';

(for example :P). Now I want to to use this variable in another form, and have at keep the same value which I assigned it in the first form. I.E in form two I want to be able to say:


ShowMessage(Username);

And have a message pop up saying HelpMePLz.

How do I do this?
  • 0

#14 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 09 April 2012 - 01:08 PM

You have answered it yourself. Just show the current content of UserName by calling (yes, exactly it is):

  ShowMessage(UserName);

Somewhere in your form two.
  • 1

#15 Carver413

Carver413

    CC Newcomer

  • Member
  • PipPip
  • 13 posts

Posted 10 April 2012 - 12:07 PM

Lazarus has a forum of it's own with almost 7000 members vs the one or two you'll find here. if you are not yet a member there then you should consider joining. If you don't yet understand Classes and objects yet then I would spend some time getting to know them. this will help to clear up some confusion as to controls form's and such.

Create a new project with to forms Form1 and Form2
save the project in a new folder.
now in Form2 add a Label
in Form1 add a button. then double click on the button and add the code

  Form2.Visible:=true;
  Form2.Label1.Caption:='Hello World';

add Unit2 to uses in Unit1

and run

your code should look like this

unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,Unit2;
type
  { TForm1 }
  TForm1 = class(TForm)
	Button1: TButton;
	procedure Button1Click(Sender: TObject);
  private
	{ private declarations }
  public
	{ public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Visible:=true;
  Form2.Label1.Caption:='Hello World';
end;
end.
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
  { TForm2 }
  TForm2 = class(TForm)
	Label1: TLabel;
	procedure FormCreate(Sender: TObject);
  private
	{ private declarations }
  public
	{ public declarations }
  end;
var
  Form2: TForm2;
implementation
{$R *.lfm}
{ TForm2 }
procedure TForm2.FormCreate(Sender: TObject);
begin
end;
end.

  • 1

#16 HelpMePlz

HelpMePlz

    CC Newcomer

  • Member
  • PipPip
  • 20 posts

Posted 11 April 2012 - 02:47 AM

Thanks! I might sign up to that forum but I am getting a lot of help here and the lazarus forum looks very advanced :S Thanks for the help!
  • 0

#17 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 12 April 2012 - 02:47 AM

@HelpMePlz

I recently posted a Delphi tutorial to convert colored bitmap to grayscale. You may want to take a look since I include detailed steps on building the GUI for its demo project.

Here is the link: http://forum.codecal...ayscale/unread/
  • 0





Also tagged with one or more of these keywords: pascal

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download