Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-02

TStringList.InsertItem

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

Consider:
Procedure TStringList.InsertItem(Index: Integer; const S: string);
and
Procedure TStringList.InsertItem(Index: Integer; const S: string; O: TObject);
1018 Procedure TStringList.InsertItem(Index: Integer; const S: string);
 1019 begin
 1020   Changing;
 1021   If FCount=Fcapacity then Grow;
 1022   If Index<FCount then
 1023     System.Move (FList^[Index],FList^[Index+1],
 1024                  (FCount-Index)*SizeOf(TStringItem));
 1025   Pointer(Flist^[Index].Fstring):=Nil;  // Needed to initialize...
 1026   Flist^[Index].FString:=S;
 1027   Flist^[Index].Fobject:=Nil;
 1028   Inc(FCount);
 1029   Changed;
 1030 end;
 1031
1032
1033 Procedure TStringList.InsertItem(Index: Integer; const S: string;
O: TObject);
 1034 begin
 1035   Changing;
 1036   If FCount=Fcapacity then Grow;
 1037   If Index<FCount then
 1038     System.Move (FList^[Index],FList^[Index+1],
 1039                  (FCount-Index)*SizeOf(TStringItem));
 1040   Pointer(Flist^[Index].Fstring):=Nil;  // Needed to initialize...
 1041   Flist^[Index].FString:=S;
 1042   Flist^[Index].FObject:=O;
 1043   Inc(FCount);
 1044   Changed;
 1045 end;

Why doesn't TStringList.InsertItem(Index: Integer; const S: string); just call TStringList.InsertItem(Index, S, nil)?

Bart

Reply by email

Michael Van Canneyt
to Bart
Bart wrote 40 lines
Hi, Consider: Procedure TStringList.InsertItem(Index: Integer; const S: string); and Procedure TStringList.InsertItem(Index: Integer; const S: string; O: TObject); 1018 Procedure TStringList.InsertItem(Index: Integer; const S: string); 1019 begin 1020 Changing; 1021 If FCount=Fcapacity then Grow; 1022 If Index<FCount then 1023 System.Move (FList^[Index],FList^[Index+1], 1024 (FCount-Index)*SizeOf(TStringItem)); 1025 Pointer(Flist^[Index].Fstring):=Nil; // Needed to initialize... 1026 Flist^[Index].FString:=S; 1027 Flist^[Index].Fobject:=Nil; 1028 Inc(FCount); 1029 Changed; 1030 end; 1031 1032 1033 Procedure TStringList.InsertItem(Index: Integer; const S: string; O: TObject); 1034 begin 1035 Changing; 1036 If FCount=Fcapacity then Grow; 1037 If Index<FCount then 1038 System.Move (FList^[Index],FList^[Index+1], 1039 (FCount-Index)*SizeOf(TStringItem)); 1040 Pointer(Flist^[Index].Fstring):=Nil; // Needed to initialize... 1041 Flist^[Index].FString:=S; 1042 Flist^[Index].FObject:=O; 1043 Inc(FCount); 1044 Changed; 1045 end; Why doesn't TStringList.InsertItem(Index: Integer; const S: string); just call TStringList.InsertItem(Index, S, nil)?

It could do that, feel free to provide a patch :)

Michael.

Reply by email