Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

string grids

hey zibidian (sorry if ive spelt your name wrong)
thank you for replying to my message, however, i am absolutely useless at programming and i dont understand the help delphi gives. ive only been learning for 2 months or something like that so its all pretty unfamiliar. i dont know if im barking up the wrong tree here but once i program delphi to fill the string grid, would i have to tell it to load file, then fill string grid all in one procedure? also for example if, on my form, i enter a date with a date time picker, would i have to turn that into string for it to load properly on the string grid? possible TDateTimeintostr?! additionally im not sure if im saving the data correctly. what is the save procedure? id be grateful if you could show me some examples of saving and loading files as well as filling in a string grid!
thank you in advance! :D

Comments

  • zibadianzibadian Posts: 6,349Member
    : hey zibidian (sorry if ive spelt your name wrong)
    : thank you for replying to my message, however, i am absolutely useless at programming and i dont understand the help delphi gives. ive only been learning for 2 months or something like that so its all pretty unfamiliar. i dont know if im barking up the wrong tree here but once i program delphi to fill the string grid, would i have to tell it to load file, then fill string grid all in one procedure? also for example if, on my form, i enter a date with a date time picker, would i have to turn that into string for it to load properly on the string grid? possible TDateTimeintostr?! additionally im not sure if im saving the data correctly. what is the save procedure? id be grateful if you could show me some examples of saving and loading files as well as filling in a string grid!
    : thank you in advance! :D
    :
    Filling a stringgrid can be done by using the build-in editor. The Options property controls if that feature is turned on or not (I don't have Delphi here, but it has a logical name). Here is an example of filling the stringgrid from a comma-delimited textfile:
    [code]
    var
    f: textfile;
    s: string;
    begin
    AssignFile(f, 'somefile.txt');
    Reset(f);
    SG1.RowCount := 0;
    while not eof(f) do
    begin
    readln(f, s); // read a line from file
    SG1.RowCount := SG1.RowCount + 1; // Add a new row
    SG1.Rows[SG1.RowCount-1].CommaText := s;
    end;
    CloseFile(f);
    [/code]
    I'm not sure what happens if there are more fields per line than Columns in the grid. So the only way to find it out is to try it.
    Saving it is very similar:
    [code]
    var
    f: textfile;
    s: string;
    i: integer;
    begin
    AssignFile(f, 'somefile.txt');
    Rewrite(f);
    for i := 0 to SG1.RowCount-1 do
    begin
    s := SG1.Rows[SG1.RowCount-1].CommaText;
    writeln(f, s);
    end;
    CloseFile(f);
    [/code]
    You can convert a date and time using the DateToStr() and TimeToStr() functions.
Sign In or Register to comment.