Stringgrid - take strings with separators and turn into separate cells

Asked

Viewed 555 times

0

greetings to all

My stringGrid already has more data coming from other locations (this image is just illustrative) I would need to throw more of this information coming from a variable in a single predetermined row filling these stringgrid cells

these strings are of unknown size for example coming from Edit or a variable where each element’s that is separated by the separator ; is displayed in sequence in separate cells in stringrid in a single row

variable := t;e;xxxx;t;Ooo

in Stringgrid cells would look like this

[ t ] [ and ] [ xxx ] [ t ] [ Ooo ]

inserir a descrição da imagem aqui

I thank anyone who can help me

  • You can use a Tstringlist, load the content and use Extractstrings to delimit the data of your variable with ";" and then scroll through the stringlist by throwing the information on the stringgrid.

  • all right Jefferson Rudolf, thanks for the tip could give me an example, using the Tstringlist,?

2 answers

0

I set up the routine to see if it helps.

var
  oSLDados : TStringList;
  sTexto   : String;
  iCont    : Integer;
begin
  sTexto   := 't;e;xxxx;t;ooo';
  oSLDados := TStringList.Create;
  try
    oSLDados.Delimiter       := ';';
    oSLDados.StrictDelimiter := True;
    oSLDados.DelimitedText   := sTexto;

    for iCont := 0 to oSLDados.Count-1 do
      StringGrid1.Cells[iCont,0] := oSLDados.Strings[iCont];
  finally
    FreeAndNil(oSLDados);
  end;
end;

0

Good Morning Jefferson Rudolf

I’ve been knocking here since dawn, with tips that you had suggested to me from Tstringlist, and I just finished, and I came to see the emails,

I’ll even leave the code in case someone needs it

Button1click(Sender: Tobject);
var
t: Tstringlist;
i:integer;
Begin
t := Tstringlist.create; // creates a class
t. text := stringReplace(Edit1.Text, '|', #13,[rfReplaceAll]);//replaces | by line break
for i := 0 to Pred(t.Count) do
Stringgrid1.Cells[i+1,2]:=t[i]; // plays all elements of Edit in stringgrid i+1 for prencher from column 2

t. free; // destroy the class
end;


Button2click(Sender: Tobject);
Begin
Stringgrid1.Rows[2]. Clear; // Clear line
end;

Thank you even for your help

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.