Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Delphi 

Globally Assign a Record Struct?

Hey Guys, was just wondering if I could somewhere globally assign a Records Struct I have... you see I don't wanna assign it anywhere in a local scope but in the global scope so it can be used anywhere:

Code
type
   Color = record
     Red : integer;
     White : integer;
     Lime : integer;
     Yellow : integer;
   end;

<...>

  With Color do
  begin
     Color.Red := 1;
     Color.White := 2;
     Color.Lime := 3;
     Color.Yellow := 4;
  end;

Any Ideas? I tried assigning itself but it won't let me..
Globally? It already is global. Even if you put record "color" into another unit, you can still use it. Please be a little more specific.
My Code:
Code
program prjTest;
{$APPTYPE CONSOLE}
uses
  UOther in 'UOther.pas';
var
Test : Color;
begin

With test do
  begin
     Red := 1;
     White := 2;
     Lime := 3;
     Yellow := 4;
  end;
end.
Code of UOther:
Code
unit UOther;
interface
type
   Color = record
     Red : integer;
     White : integer;
     Lime : integer;
     Yellow : integer;
   end;
implementation
end.
(Jun 16, 2016 06:28 PM)Volty Wrote:  Globally? It already is global. Even if you put record "color" into another unit, you can still use it. Please be a little more specific.
My Code:
Code
program prjTest;
{$APPTYPE CONSOLE}
uses
  UOther in 'UOther.pas';
var
Test : Color;
begin

With test do
  begin
     Red := 1;
     White := 2;
     Lime := 3;
     Yellow := 4;
  end;
end.
Code of UOther:
Code
unit UOther;
interface
type
   Color = record
     Red : integer;
     White : integer;
     Lime : integer;
     Yellow : integer;
   end;
implementation
end.

ok alright it's global, but I don't wanna use it in another unit, I wanna use it locally and within my app.. how can I call Color.Red and be read without giving me the error: "Expression has to be constant" or idk... ?
(Jun 17, 2016 10:38 AM)ReversɘЯ Wrote:  ok alright it's global, but I don't wanna use it in another unit, I wanna use it locally and within my app.. how can I call Color.Red and be read without giving me the error: "Expression has to be constant" or idk... ?

Maybe this? (No errors for me)
Code
program prjTest;
{$APPTYPE CONSOLE}
uses Dialogs,SysUtils;

type
   Color = record
     Red : integer;
     White : integer;
   end;

var
Test : Color;
begin
Test.Red := 10;
ShowMessage(IntToStr(Test.Red));
end.
(Jun 17, 2016 12:42 PM)Volty Wrote:  Maybe this? (No errors for me)
Code
program prjTest;
{$APPTYPE CONSOLE}
uses Dialogs,SysUtils;

type
   Color = record
     Red : integer;
     White : integer;
   end;

var
Test : Color;
begin
Test.Red := 10;
ShowMessage(IntToStr(Test.Red));
end.

well it's working, i just wanted to use it in a function where I'm using a Case scenario:

Code
function yadayada(colorid: integer): string;
Case colorID do
begin
      Colors.Red:
                  begin
                          <...>
                  end;

      Colors.White:
                  begin
                          <...>
                  end;
end;
end;

it gives me an error saying Expression must be constant. or something like that... I just use it like this anyways...

Code
function yadayada(colorid: integer): string;
Case colorID do
begin
      1:
                  begin
                          <...>
                  end;

      2:
                  begin
                          <...>
                  end;
end;
end;

Thx for helping out though


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by .eXeAug 9, 2023 04:41 AM 0 89 Aug 9, 2023 04:41 AM
Last Post: .eXe
[Perl] by slysavvyMar 20, 2017 01:10 PM 0 243 Mar 20, 2017 01:10 PM
Last Post: slysavvy
by Annabelle LeeSep 5, 2016 04:38 PM 1 122 Sep 5, 2016 04:38 PM
Last Post: Sakuto