Board index » delphi » String Assignment

String Assignment

Assigning S to IdStrs[] causes an error.
I would really like IdStrs to ba ShortString but I cann't figure out how
to assign that either.

What simple thing am I missing.

Thanks,
Sdiebel

Var
    IdStrs : array[0..11] of String;

Procedure test;
Var F : TextFile;
    S : String;
    C, i : Integer;

begin
     with OpenDialog1 do
     begin
       Filter := 'Id File (I_*.*) | I_*.*';
       if Execute then
       begin
        AssignFile(F, FileName);
        FileMode := 0;  { Set file access to read only }
        Reset(F);
        i := 1;
        with IdForm Do
        for C := 0 to ComponentCount -1 do
        begin
             if Components[C] is TrscEdit then
             begin
                  Readln(F,S);
                  TrscEdit(Components[C]).Text := S;
                  IdStrs[i] := S;
                  Inc(i);
             end;
        end;
        CloseFile(F);
       end;
     end
end;

 

Re:String Assignment


Quote
Stephen Diebel wrote:
> Assigning S to IdStrs[] causes an error.
> I would really like IdStrs to ba ShortString but I cann't figure out how
> to assign that either.

There's nothing obvious from the code you've supplied, but it's a
bit incomplete. I would suspect that you may be exceeding the
bounds of the array IdStrs. Do you have range checking enabled?
If so, do so and try it.

Good luck.

Kurt

Re:String Assignment


Quote
Stephen Diebel wrote...
> Assigning S to IdStrs[] causes an error.
> I would really like IdStrs to ba ShortString but I cann't figure out how
> to assign that either.

Your array is defined from 0..11 in your file read code you
initialize i width 1 instead of 0. Could this be your problem?

--
Pieter

Re:String Assignment


Yes it was an index error.

Thanks!

Quote
Pieter Zijlstra wrote:
> Stephen Diebel wrote...
> > Assigning S to IdStrs[] causes an error.
> > I would really like IdStrs to ba ShortString but I cann't figure out how
> > to assign that either.

> Your array is defined from 0..11 in your file read code you
> initialize i width 1 instead of 0. Could this be your problem?

> --
> Pieter

Other Threads