diff --git a/fcl/inc/strings.inc b/fcl/inc/strings.inc index 7117c6d48c..3604eda287 100644 --- a/fcl/inc/strings.inc +++ b/fcl/inc/strings.inc @@ -32,7 +32,7 @@ begin begin I:=I+1; J:=J+1; - if S[i]=Quote then + if S[i]=Quote then begin System.Insert(Result,Quote,J); J:=J+1; @@ -47,7 +47,7 @@ Var I : Longint; begin result:=''; - For i:=0 to count-1 do + For i:=0 to count-1 do begin Result:=Result+QuoteString (Strings[I],'"'); if I#0 do begin - If (P1^='"') and (P1[1]<>'"') then + If (P1^='"') and (P1[1]<>'"') then break; P1:=P1+1; If P1^='"' then P1:=P1+1; end; - // P1 points to last quote, or to #0; + // P1 points to last quote, or to #0; P:=P+1; - If P1-P>0 then + If P1-P>0 then begin - SetLength(Result,(P1-P)); + SetLength(Result,P1-P); L:=Pointer(Result); Move (P^,L^,P1-P); P:=P1+1; @@ -184,7 +184,7 @@ end; -Procedure TStrings.DefineProperties(Filer: TFiler); +Procedure TStrings.DefineProperties(Filer: TFiler); begin end; @@ -200,7 +200,7 @@ end; -Function TStrings.GetCapacity: Integer; +Function TStrings.GetCapacity: Integer; begin Result:=Count; @@ -208,7 +208,7 @@ end; -Function TStrings.GetObject(Index: Integer): TObject; +Function TStrings.GetObject(Index: Integer): TObject; begin Result:=Nil; @@ -216,7 +216,7 @@ end; -Function TStrings.GetTextStr: string; +Function TStrings.GetTextStr: string; Const {$ifdef linux} @@ -226,7 +226,7 @@ Const {$endif} Var P : Pchar; - I,L : Longint; + I,L : Longint; S : String; PS : Pointer; @@ -235,12 +235,12 @@ begin L:=0; For I:=0 to count-1 do L:=L+Length(Strings[I])+NewLineSize; Setlength(Result,0); - P:=Pointer(Result); + P:=Pointer(Result); For i:=0 To count-1 do begin S:=Strings[I]; L:=Length(S); - if L<>0 then + if L<>0 then System.Move(Pointer(S)^,P^,L); P:=P+L; p[0]:=#10; @@ -253,7 +253,7 @@ end; -Procedure TStrings.Put(Index: Integer; const S: string); +Procedure TStrings.Put(Index: Integer; const S: string); Var Obj : TObject; @@ -265,7 +265,7 @@ end; -Procedure TStrings.PutObject(Index: Integer; AObject: TObject); +Procedure TStrings.PutObject(Index: Integer; AObject: TObject); begin // Empty. @@ -273,14 +273,14 @@ end; -Procedure TStrings.SetCapacity(NewCapacity: Integer); +Procedure TStrings.SetCapacity(NewCapacity: Integer); begin // Empty. end; -Procedure TStrings.SetTextStr(const Value: string); +Procedure TStrings.SetTextStr(const Value: string); begin SetText(PChar(Value)); @@ -288,14 +288,14 @@ end; -Procedure TStrings.SetUpdateState(Updating: Boolean); +Procedure TStrings.SetUpdateState(Updating: Boolean); begin end; -destructor TSTrings.Destroy; +destructor TSTrings.Destroy; begin inherited destroy; @@ -303,7 +303,7 @@ end; -Function TStrings.Add(const S: string): Integer; +Function TStrings.Add(const S: string): Integer; begin Result:=Count; @@ -312,7 +312,7 @@ end; -Function TStrings.AddObject(const S: string; AObject: TObject): Integer; +Function TStrings.AddObject(const S: string; AObject: TObject): Integer; begin Result:=Add(S); @@ -329,7 +329,7 @@ end; -Procedure TStrings.AddStrings(TheStrings: TStrings); +Procedure TStrings.AddStrings(TheStrings: TStrings); Var Runner : longint; @@ -340,7 +340,7 @@ end; -Procedure TStrings.Assign(Source: TPersistent); +Procedure TStrings.Assign(Source: TPersistent); begin If Source is TStrings then @@ -376,14 +376,14 @@ begin Result:=False; Nr:=Self.Count; if Nr<>TheStrings.Count then exit; - For Runner:=0 to Nr-1 do + For Runner:=0 to Nr-1 do If Strings[Runner]<>TheStrings[Runner] then exit; Result:=True; end; -Procedure TStrings.Exchange(Index1, Index2: Integer); +Procedure TStrings.Exchange(Index1, Index2: Integer); Var Obj : TObject; @@ -400,7 +400,7 @@ end; -Function TStrings.GetText: PChar; +Function TStrings.GetText: PChar; begin Result:=StrNew(Pchar(Self.Text)); @@ -408,7 +408,7 @@ end; -Function TStrings.IndexOf(const S: string): Integer; +Function TStrings.IndexOf(const S: string): Integer; begin @@ -431,7 +431,7 @@ begin if (len>0) and (Name=Copy(Strings[Result],1,Len)) then exit; inc(result); end; - result:=-1; + result:=-1; end; @@ -456,7 +456,7 @@ end; -Procedure TStrings.LoadFromFile(const FileName: string); +Procedure TStrings.LoadFromFile(const FileName: string); Var TheStream : TFileStream; @@ -468,7 +468,7 @@ end; -Procedure TStrings.LoadFromStream(Stream: TStream); +Procedure TStrings.LoadFromStream(Stream: TStream); begin Text:=Stream.ReadAnsiString; @@ -476,7 +476,7 @@ end; -Procedure TStrings.Move(CurIndex, NewIndex: Integer); +Procedure TStrings.Move(CurIndex, NewIndex: Integer); Var Obj : TObject; Str : String; @@ -485,12 +485,12 @@ begin Obj:=Objects[CurIndex]; Str:=Strings[CurIndex]; Delete(Curindex); - InsertObject(NewIndex,Str,Obj); + InsertObject(NewIndex,Str,Obj); end; -Procedure TStrings.SaveToFile(const FileName: string); +Procedure TStrings.SaveToFile(const FileName: string); Var TheStream : TFileStream; @@ -502,7 +502,7 @@ end; -Procedure TStrings.SaveToStream(Stream: TStream); +Procedure TStrings.SaveToStream(Stream: TStream); begin Stream.WriteAnsiString(Text); @@ -526,7 +526,7 @@ begin end; -Procedure TStrings.SetText(TheText: PChar); +Procedure TStrings.SetText(TheText: PChar); Var S : String; @@ -563,11 +563,11 @@ Var Extra : Longint; begin If FCapacity>64 then Extra:=FCapacity Div 4 - Else If FCapacity>8 Then + Else If FCapacity>8 Then Extra:=16 - Else + Else Extra:=4; - SetCapacity(FCapacity+Extra); + SetCapacity(FCapacity+Extra); end; @@ -585,7 +585,7 @@ begin Repeat While AnsiCompareText(Flist^[I].Fstring,Pivot)<0 do Inc(I); While AnsiCompareText(Flist^[J].Fstring,Pivot)>0 do Dec(J); - If I<=J then + If I<=J then begin ExchangeItems(I,J); // No check, indices are correct. Inc(I); @@ -627,7 +627,7 @@ end; -Procedure TStringList.Changed; +Procedure TStringList.Changed; begin If (FUpdateCount=0) Then @@ -637,7 +637,7 @@ end; -Procedure TStringList.Changing; +Procedure TStringList.Changing; begin If FUpdateCount=0 then @@ -647,9 +647,10 @@ end; -Function TStringList.Get(Index: Integer): string; +Function TStringList.Get(Index: Integer): string; begin + pointer(Result):=nil; If (Index<0) or (INdex>=Fcount) then Error (SListIndexError,Index); Result:=Flist^[Index].FString; @@ -657,7 +658,7 @@ end; -Function TStringList.GetCapacity: Integer; +Function TStringList.GetCapacity: Integer; begin Result:=FCapacity; @@ -665,7 +666,7 @@ end; -Function TStringList.GetCount: Integer; +Function TStringList.GetCount: Integer; begin Result:=FCount; @@ -673,7 +674,7 @@ end; -Function TStringList.GetObject(Index: Integer): TObject; +Function TStringList.GetObject(Index: Integer): TObject; begin If (Index<0) or (INdex>=Fcount) then @@ -683,10 +684,10 @@ end; -Procedure TStringList.Put(Index: Integer; const S: string); +Procedure TStringList.Put(Index: Integer; const S: string); begin - If Sorted then + If Sorted then Error(SSortedListError,0); If (Index<0) or (INdex>=Fcount) then Error (SListIndexError,Index); @@ -697,52 +698,53 @@ end; -Procedure TStringList.PutObject(Index: Integer; AObject: TObject); +Procedure TStringList.PutObject(Index: Integer; AObject: TObject); begin If (Index<0) or (INdex>=Fcount) then Error (SListIndexError,Index); Changing; - Flist^[Index].FObject:=AObject; + Flist^[Index].FObject:=AObject; Changed; end; -Procedure TStringList.SetCapacity(NewCapacity: Integer); +Procedure TStringList.SetCapacity(NewCapacity: Integer); + +Var NewList,ToFree : Pointer; -Var NewList : Pointer; - MSize : Longint; - begin - If (NewCapacity<0) then - Error (SListCapacityError,NewCapacity); + If (NewCapacity<0) then + Error (SListCapacityError,NewCapacity); If NewCapacity>FCapacity then begin GetMem (NewList,NewCapacity*SizeOf(TStringItem)); If NewList=Nil then + //!! Find another one here !! Error (SListCapacityError,NewCapacity); If Assigned(FList) then begin - MSize:=FCapacity*Sizeof(TStringItem); - System.Move (FList^,NewList^,MSize); - FillWord (Pchar(NewList)[MSize],(NewCapacity-FCapacity)*WordRatio, 0); - FreeMem (Flist,MSize); + System.Move (FList^,NewList^,FCapacity*Sizeof(TStringItem)); + FillChar (PStringItemList(NewList)^[FCapacity],(NewCapacity-FCapacity)*sizeof(TStringItem), 0); + FreeMem (Flist,FCapacity*SizeOf(TStringItem)); end; Flist:=NewList; FCapacity:=NewCapacity; end else if NewCapacity=FCount) then @@ -814,19 +816,19 @@ end; -Procedure TStringList.Exchange(Index1, Index2: Integer); +Procedure TStringList.Exchange(Index1, Index2: Integer); begin - If (Index1<0) or (Index1>=FCount) then + If (Index1<0) or (Index1>=FCount) then Error(SListIndexError,Index1); - If (Index2<0) or (Index2>=FCount) then + If (Index2<0) or (Index2>=FCount) then Error(SListIndexError,Index1); Changing; ExchangeItems(Index1,Index2); changed; end; -Function TStringList.Find(const S: string; var Index: Integer): Boolean; +Function TStringList.Find(const S: string; var Index: Integer): Boolean; { Searches for the first string <= S, returns True if exact match, sets index to the index f the found string. } @@ -842,7 +844,7 @@ begin begin I:=(L+R) div 2; Temp:=AnsiCompareText(FList^ [I].FString,S); - If Temp<0 then + If Temp<0 then L:=I+1 else begin @@ -854,38 +856,38 @@ begin end; end; end; - Index:=L; + Index:=L; end; -Function TStringList.IndexOf(const S: string): Integer; +Function TStringList.IndexOf(const S: string): Integer; begin - If Not Sorted then + If Not Sorted then Result:=Inherited indexOf(S) else // faster using binary search... - If Not Find (S,Result) then + If Not Find (S,Result) then Result:=-1; end; -Procedure TStringList.Insert(Index: Integer; const S: string); +Procedure TStringList.Insert(Index: Integer; const S: string); begin If Sorted then Error (SSortedListError,0) - else + else If (Index<0) or (Index>FCount) then Error (SListIndexError,Index) - else + else InsertItem (Index,S); end; -Procedure TStringList.Sort; +Procedure TStringList.Sort; begin If Not Sorted and FCount>1 then @@ -898,8 +900,8 @@ end; { $Log$ - Revision 1.6 1998-11-09 10:07:24 michael - + Bugfix in setcapacity, sizes were wrong + Revision 1.7 1998-11-12 23:43:44 peter + * fixed tstringlist.setcapacity for growing Revision 1.5 1998/10/30 14:52:52 michael + Added format in interface