Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dynamic creation of TStringList

Featured Replies

Hello

Can anyone tell me how to dynamically create a string list, based on a prefix and a loop counter.

Hopefully, this pusedo code below will help explain what i am looking for...

Delphi 7.

for i:=0to Count-1do

begin

StringListPrefix+:=TStringList.Create;

Thanks for any help!


Do you mean something like this?

Type
TStringListArray = Array Of TStringList;

Var
StringListArray = TStringListArray;

Procedure DestroyStringLists(Var ListArray: TStringListArray);
Var I: Integer;
Begin
For I := 0 To High(ListArray) Do ListArray[I].Free;
SetLength(ListArray,0);
End;

Procedure AllocateStringLists(Var ListArray: TStringListArray; Count: Integer);
Begin
// If anything is already in the list, get rid of it

DestroyStringLists(ListArray);

// Allocate String Lists

SetLength(ListArray,Count);
For I := 0 To Count - 1 Do ListArray[I] := TStringList.Create;
End;

Begin
// Test code

AllocateStringLists(StringListArray);

// Do something with the lists we created...

// Destroy everything

DestroyStringLists(StringListArray);
End;

You could also accomplish this by using a TStringList itself instead of an open array, but this is type-safe.

  • Author

Hello WildBill,

Yes! that was exactly what i was after. However, i ended up rewriting the whole function without the need for this unknown amount of string lists... its quite a good wee idea, hope you dont mind if i add it to my collection :)

  • 3 weeks later...

You're welcome. If you ever need associative lists (hashes), you might want to take a look at the STHashes unit in SmoothText's source code. It's in the Win2000 section. Delphi never came with decent hash code and I needed to write it to fill the gap.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.