[fpc-pascal] TStringList.InsertItem

Michael Van Canneyt michael at freepascal.org
Fri Feb 8 13:32:24 CET 2013



On Fri, 8 Feb 2013, Bart wrote:

> 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.



More information about the fpc-pascal mailing list