Board index » delphi » How can I assign a value to a Var when I declare it?

How can I assign a value to a Var when I declare it?

Is there a way I can assign a value to a Var at the same time it is declared
in the source ?

 

Re:How can I assign a value to a Var when I declare it?


One way i know is

const i:integer = 13

Its from Pascal, maybe theres a better way in Delphi i havent discovered
yet.

--
Andreas Klein
Remove XXX from my eMail

Tob schrieb in Nachricht <35760c1...@204.239.181.11>...

Quote
>Is there a way I can assign a value to a Var at the same time it is
declared
>in the source ?

Re:How can I assign a value to a Var when I declare it?


Quote
In article <6l5n2p$8h...@news.metronet.de> "Andreas Klein" <XXXa-k...@metronet.de> writes:
>From: "Andreas Klein" <XXXa-k...@metronet.de>
>Subject: Re: How can I assign a value to a Var when I declare it?
>Date: Thu, 4 Jun 1998 10:07:32 +0200
>One way i know is
>const i:integer = 13
>Its from Pascal, maybe theres a better way in Delphi i havent discovered
>yet.

This is just for Delphi 1. Using Delphi 2 or 3 you do the same thing, but a
constant IS a constant there. In Delphi 2 or 3 you can do the same with
global vars:

var i: integer = 13
^^^

Daniel Berg

Quote
>--
>Andreas Klein
>Remove XXX from my eMail

Re:How can I assign a value to a Var when I declare it?


  Actually, you can't unless it's a global variable....   What's wrong with
declaring in the beginning of the code?

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us

Quote
Andreas Klein wrote in message <6l5n2p$8h...@news.metronet.de>...
>One way i know is

>const i:integer = 13

>Its from Pascal, maybe theres a better way in Delphi i havent discovered
>yet.

>--
>Andreas Klein
>Remove XXX from my eMail

>Tob schrieb in Nachricht <35760c1...@204.239.181.11>...
>>Is there a way I can assign a value to a Var at the same time it is
>declared
>>in the source ?

Re:How can I assign a value to a Var when I declare it?


Remember that using 'const =' assings only once the value, even if your
program calls subsequently the function.

procedure Test;
const i : integer = 10
begin
  ShowMessage(' i = '+IntToStr(i)); { prints 10,11,12,...}
   Inc (i);
end;

is not the same as :

procedure Test;
var i : integer
begin
  i := 10;
  ShowMessage(' i = '+IntToStr(i)); {always 10}
  Inc (i);
end;

--------------------------------------------------------------------
{*word*137} software engineer

ing. Pascal Dutilleul
Pascal.Dutill...@ping.be                  Borland Connections Member
--------------------------------------------------------------------

Re:How can I assign a value to a Var when I declare it?


On Thu, 4 Jun 1998 12:59:27 -0700, "Jason Wallace"

Quote
<Dark...@SLSoftware.reno.nv.us> wrote:
>  Actually, you can't unless it's a global variable....   What's wrong with
>declaring in the beginning of the code?

Or even my personal favorite:

unit VarDef;

interface

var
  AppIsBusy: boolean;

implementation

initialization //here's the trick
  AppIsBusy := False
end.

Even before Delphi creates the first form, it executes any
initialization code assigned to units in the project.

Other Threads