Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4015246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:35:45+00:00 2026-05-20T09:35:45+00:00

Saving, editing and loading information. The information that I want to load is something

  • 0

Saving, editing and loading information. The information that I want to load is something I will add myself. Each line of information will contain 4 pieces, (string, integer, string, integer). Via 4 seperate edit boxes and a button I will add this information to a ‘database’ (not sure if I need a database or if it can be done via something like a Tstringlist). Everytime the button is clicked it will added the content that is typed at that moment in the ‘database’.

The only demand of the saved data is when I type the first string from the list it could place the rest of the information that belongs to it in a memobox or edit boxes as well. So I suppose I have to be able to search. Just want to keep it as simple as possible. There will only be about 10 to 15 lines of information. and if possible it would be good if I can load them again a later time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:35:46+00:00Added an answer on May 20, 2026 at 9:35 am

    Here’s some very basic code that should get you on your way. There’s no error checking, and you’ll no doubt want to develop it and modify it further. The point is that there should be some ideas to help you write code that works for you.

    Now that I have comma-separated the fields, but made no attempt to handle the appearance of commas in any of the values. If this is a problem then choose a different delimiter, or escape the commas. I had toyed with writing each field on its own line (effectively using a newline as the separator), but this makes the reading code more tricky to write.

    Again, the main point is that this is not final production code, but is intended to give you a starting point.

    function Split(const s: string; Separator: char): TStringDynArray;
    var
      i, ItemIndex: Integer;
      len: Integer;
      SeparatorCount: Integer;
      Start: Integer;
    begin
      len := Length(s);
      if len=0 then begin
        Result := nil;
        exit;
      end;
    
      SeparatorCount := 0;
      for i := 1 to len do begin
        if s[i]=Separator then begin
          inc(SeparatorCount);
        end;
      end;
    
      SetLength(Result, SeparatorCount+1);
      ItemIndex := 0;
      Start := 1;
      for i := 1 to len do begin
        if s[i]=Separator then begin
          Result[ItemIndex] := Copy(s, Start, i-Start);
          inc(ItemIndex);
          Start := i+1;
        end;
      end;
      Result[ItemIndex] := Copy(s, Start, len-Start+1);
    end;
    
    type
      TValue = record
        i1, i2: Integer;
        s: string;
      end;
    
      TMyDict = class(TDictionary<string,TValue>)
      public
        procedure SaveToFile(const FileName: string);
        procedure LoadFromFile(const FileName: string);
      end;
    
    { TMyDict }
    
    procedure TMyDict.SaveToFile(const FileName: string);
    var
      Strings: TStringList;
      Item: TPair<string,TValue>;
    begin
      Strings := TStringList.Create;
      Try
        for Item in Self do begin
          Strings.Add(Format(
            '%s,%s,%d,%d',
            [Item.Key, Item.Value.s, Item.Value.i1, Item.Value.i2]
          ));
        end;
        Strings.SaveToFile(FileName);
      Finally
        FreeAndNil(Strings);
      End;
    end;
    
    procedure TMyDict.LoadFromFile(const FileName: string);
    var
      Strings: TStringList;
      Item: TPair<string,TValue>;
      Line: string;
      Fields: TStringDynArray;
    begin
      Strings := TStringList.Create;
      Try
        Strings.LoadFromFile(FileName);
        for Line in Strings do begin
          Fields := Split(Line, ',');
          Assert(Length(Fields)=4);
          Item.Key := Fields[0];
          Item.Value.s := Fields[1];
          Item.Value.i1 := StrToInt(Fields[2]);
          Item.Value.i2 := StrToInt(Fields[3]);
          Add(Item.Key, Item.Value);
        end;
      Finally
        FreeAndNil(Strings);
      End;
    end;
    

    Note that you don’t attempt to search the file on disk. You simply load it into memory, into the dictionary and look things up from there.

    A dictionary is great when you always use the same key. If you have multiple keys then a dictionary is less convenient, but who cares about the performance impact if you’ve only got 15 records?!

    Disclaimer: I’ve not run the code, I’ve not tested it, etc. etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am finding myself editing a lot of files that are read-only. I usually
I'm using Zend Framework with Doctrine. I'm creating an object, editing, then saving it.
What's the best method for editing and saving a JSON file on the iPhone/iPod?
Is there a pipeline I can add to and/or event to intercept that would
I have a question regarding editing/saving data in database using Django. I have template
I am saving image into isolated storage each image have a different imageFileName. But
I found an article on image processing from here: http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing Everything works fine. I
My image editing app is saving some important data in the documents directory. In
We have a requirement to prevent saving additional copies of PDFs that exist out
I am using jquery DataTables and jEditable to allow inline editing of EACH CELL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.