Board index » delphi » how can I change the colour 64 TShape circles based on a Binary string

how can I change the colour 64 TShape circles based on a Binary string

I have 64 circles which need to be either black filled or clear
depending on a 64 bit binary number.
I have tried the following but it give me an error saying 'undeclared
identifier circle'

Var
        P : Integer;
Begin
        For P := 1 to Length(BinaryString) do
        begin
                Case BinaryString[P] of
                '0' : Circle[P].pen.mode :=  pmCopy;
                '1' : Circle[P].pen.mode := pmBlack;
                End;
        End;
End;

The Tshape circles are named Circle1 to Circle64

Any help any one can give is greatly appreciated.
I'm using Delphi 4

Thanks
Ian

i...@banneruk.demon.co.uk

 

Re:how can I change the colour 64 TShape circles based on a Binary string


You have declared 64 tShapes as individual variables (Circle1 thru
Circle64). You cannot address them as an array, (which is what you do in
your code snipet). Try this instead:

var    p : integer;
        aShape : tComponent;

begin
for p := 1 to Length (BinaryString) do
    begin
    aShape := FindComponent ('Circle' + IntToStr (p));
    if (aShape <> nil) and (aShape is tShape)
    then begin
        with tShape (aShape).pen do
            begin
            case BinaryString [p] of
                '0' : mode := pmCopy;
                '1' : mode := pmBlack;
                end;    // of case
            end;    // of with
        end
    else raise exception.Create ('Unable to locate tShape named "Circle' +
IntToStr (p) + '".');
    end;    // of for
end;

Quote
Ian Manning <i...@banneruk.demon.co.uk> wrote in message

news:5i3+NxvWJyTxnTzdM32FfL1YLajT@4ax.com...
Quote

> I have 64 circles which need to be either black filled or clear
> depending on a 64 bit binary number.
> I have tried the following but it give me an error saying 'undeclared
> identifier circle'

> Var
> P : Integer;
> Begin
> For P := 1 to Length(BinaryString) do
> begin
> Case BinaryString[P] of
> '0' : Circle[P].pen.mode :=  pmCopy;
> '1' : Circle[P].pen.mode := pmBlack;
> End;
> End;
> End;

> The Tshape circles are named Circle1 to Circle64

> Any help any one can give is greatly appreciated.
> I'm using Delphi 4

> Thanks
> Ian

> i...@banneruk.demon.co.uk

Other Threads