⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 synedittextbuffer.pas

📁 DBDesigner 4 is a database design system that integrates database design, modelling, creation and ma
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  tmpIndex: Integer;
begin
  BeginUpdate;
  s1 := s;                                                                      //Fiala
  tmpIndex := Index;                                                            //Fiala
  repeat                                                                        //Fiala
    if fCount = fCapacity then
      Grow;
    if tmpIndex < fCount then begin
      System.Move(fList^[tmpIndex], fList^[tmpIndex + 1],
        (fCount - tmpIndex) * SynEditStringRecSize);
    end;
    fIndexOfLongestLine := -1;                                                  //mh 2000-10-19
    with fList^[tmpIndex] do begin
      Pointer(fString) := nil;
      fString := WrapString(s1);                                                //Fiala
      fObject := nil;
      fRange := NullRange;
      fExpandedLength := -1;
      fFlags := [sfExpandedLengthUnknown];
      if Index <> tmpIndex then
        Include( fFlags, sfWrapped );
    end;
    Inc(tmpIndex);
    Inc(fCount);
  until Length(s1) = 0;                                                         //Fiala
  EndUpdate;
(*//Old Code, left for reference
  BeginUpdate;
  if fCount = fCapacity then
    Grow;
  if Index < fCount then begin
    System.Move(fList^[Index], fList^[Index + 1],
      (fCount - Index) * SynEditStringRecSize);
  end;
  fIndexOfLongestLine := -1;                                                    //mh 2000-10-19
  with fList^[Index] do begin
    Pointer(fString) := nil;
    fString := S;
    fObject := nil;
    fRange := NullRange;
{begin}                                                                         //mh 2000-10-19
    fExpandedLength := -1;
    fFlags := [sfExpandedLengthUnknown];
{end}                                                                           //mh 2000-10-19
  end;
  Inc(fCount);
  EndUpdate;
*)
end;

{begin}                                                                         // DJLP 2000-11-01
procedure TSynEditStringList.InsertLines(Index, NumLines: integer);
begin
  if (Index < 0) or (Index > fCount) then
    ListIndexOutOfBounds(Index);
  if NumLines > 0 then begin
    BeginUpdate;
    try
      SetCapacity(fCount + NumLines);
      if Index < fCount then begin
        System.Move(fList^[Index], fList^[Index + NumLines],
          (fCount - Index) * SynEditStringRecSize);
      end;
      FillChar(fList^[Index], NumLines * SynEditStringRecSize, 0);
      Inc(fCount, NumLines);
      if Assigned(fOnAdded) then
        fOnAdded(Index, '');
    finally
      EndUpdate;
    end;
  end;
end;

procedure TSynEditStringList.InsertStrings(Index: integer;
  NewStrings: TStrings);
var
  i, Cnt: integer;
begin
  Cnt := NewStrings.Count;
  if Cnt > 0 then begin
    BeginUpdate;
    try
    InsertLines(Index, Cnt);
    for i := 0 to Cnt - 1 do
      Strings[Index + i] := NewStrings[i];
    finally
      EndUpdate;
    end;
  end;
end;
{end}                                                                           // DJLP 2000-11-01

procedure TSynEditStringList.LoadFromFile(const FileName: string);
var
//  Reader: TSynEditFileReader;                                                 //Fiala
  Stream: TStream;
{begin}                                                                         //Fiala
begin
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
  try
    LoadFromStream(Stream);
  finally
    Stream.Free;
  end;

(*//Old Code, for reference
  Reader := TSynEditFileReader.Create(FileName);
  try
    BeginUpdate;
    try
      Clear;
      while not Reader.EOF do
        Add(Reader.ReadLine);
      fFileFormat := Reader.FileFormat;
    finally
      EndUpdate;
    end;
  finally
    Reader.Free;
  end;
*)
end;

{begin}                                                                         //Fiala 2001-12-17
procedure TSynEditStringList.LoadFromStream(Stream: TStream);
var
  Size: Integer;
  S, S1: string;
  P, Start: PChar;
  fCR, fLF: Boolean;
  iPos: Integer;
begin
  fCR := False;
  fLF := False;
  try
    BeginUpdate;
    Size := Stream.Size;
    Stream.Position := 0;
    SetString(S, nil, Size);
    Stream.Read(Pointer(S)^, Size);

    Clear;
    P := Pointer(S);
    if P <> nil then
    begin
      iPos := 0;
      while (iPos < Size) do // (P^ <> #0) do
      begin
        Start := P;
        while not (P^ in [#0, #10, #13]) do
        begin
          Inc(P);
          Inc(iPos);
        end;
        SetString(S1, Start, P - Start);
        Add(S1);
        if (P^ = #13) then
        begin
          fCR := True;
          Inc(P);
          Inc(iPos);
        end;
        if (P^ = #10) then
        begin
          fLF := True;
          Inc(P);
          Inc(iPos);
        end;
        if (P^ = #0) then
        begin
          Inc(P);
          Inc(iPos);
        end;
      end;
      { keep the old format of the file }
      if (not AppendNewLineAtEOF) and (S[Size] in [#10,#13]) then
        Add('');
    end;
  finally
    EndUpdate;
  end;
  if fCR and not fLF then
    fFileFormat := sffMac
  else if fLF and not fCR then
    fFileFormat := sffUnix
  else
    fFileFormat := sffDos;
end;

procedure TSynEditStringList.SaveToStream(Stream: TStream);
var
  S, S1: string;
  I, L, Size: Integer;
  P: PChar;
  LineEndLength: Integer;
begin
  Size := 0;
  if FileFormat in [sffMac, sffUnix] then
    LineEndLength := 1
  else
    LineEndLength := 2;
  for I := 0 to Count - 1 do Inc(Size, Length(Strings[I]) + LineEndLength);
  if not AppendNewLineAtEOF then
    Dec( Size, LineEndLength );
  SetString(S, nil, Size);
  P := Pointer(S);
  for I := 0 to Count - 1 do begin
    S1 := Strings[I];
    L := Length(S1);
    if L <> 0 then
    begin
      System.Move(Pointer(S1)^, P^, L);
      Inc(P, L);
    end;
    //GBN 2002-04-16
    //Do not add new line to last line
    if (I < Count-1) or (AppendNewLineAtEOF) then begin
      if FileFormat = sffMac then begin
        P^ := #13;
        Inc(P);
      end else
      if FileFormat = sffUnix then begin
        P^ := #10;
        Inc(P);
      end else begin
        P^ := #13;
        Inc(P);
        P^ := #10;
        Inc(P);
      end;
    end;
  end;
  Stream.WriteBuffer(Pointer(S)^, Length(S));
end;
{end}                                                                           //Fiala 2001-12-17

procedure TSynEditStringList.Put(Index: integer; const S: string);
begin
  if (Index = 0) and (fCount = 0) or (fCount = Index) then                      //Fiala 2001-12-17
    Add(S)
  else begin
    if (Index < 0) or (Index >= fCount) then
      ListIndexOutOfBounds(Index);
    BeginUpdate;
{begin}                                                                         //mh 2000-10-19
    fIndexOfLongestLine := -1;
    with fList^[Index] do begin
      Include(fFlags, sfExpandedLengthUnknown);
      Exclude(fFlags, sfHasTabs);
      Exclude(fFlags, sfHasNoTabs);
      fString := S;
    end;
{end}                                                                           //mh 2000-10-19
    if Assigned(fOnPutted) then
      fOnPutted(Index, S);
    EndUpdate;
  end;
end;

procedure TSynEditStringList.PutObject(Index: integer; AObject: TObject);
begin
  if (Index < 0) or (Index >= fCount) then
    ListIndexOutOfBounds(Index);
  BeginUpdate;
  fList^[Index].fObject := AObject;
  EndUpdate;
end;

procedure TSynEditStringList.PutRange(Index: integer; ARange: TSynEditRange);
begin
  if (Index < 0) or (Index >= fCount) then
    ListIndexOutOfBounds(Index);
  BeginUpdate;
  fList^[Index].fRange := ARange;
  EndUpdate;
end;

{begin}                                                                         //Fiala 2001-12-17
procedure TSynEditStringList.SaveToFile(const FileName: string);
var
  Writer: TSynEditFileWriter;
  i, j: integer;
  s: string;
begin
  Writer := TSynEditFileWriter.Create(FileName);
  try
    Writer.FileFormat := fFileFormat;
    i := 0;
    while i < fCount do begin
      s := Get(i);
      j := i + 1;
      if fWordWrap then
        while (j < fCount) and (sfWrapped in fList^[j].fFlags) do begin
          s := s + Get(j);
          inc(j);
        end;
      i := j;
      //GBN 2002-04-16
      if (i<fCount) or (AppendNewLineAtEOF) then Writer.WriteLine(s, fFileFormat)
      else Writer.Write(S);
    end;
  finally
    Writer.Free;
  end;
end;
{end}                                                                           //Fiala 2001-12-17
(*//Old code, for reference
procedure TSynEditStringList.SaveToFile(const FileName: string);
var
  Writer: TSynEditFileWriter;
  i: integer;
begin
  Writer := TSynEditFileWriter.Create(FileName);
  try
    Writer.FileFormat := fFileFormat;
    for i := 0 to fCount - 1 do
      Writer.WriteLine(Get(i));
  finally
    Writer.Free;
  end;
end;
*)
procedure TSynEditStringList.SetCapacity(NewCapacity: integer);
begin
  ReallocMem(fList, NewCapacity * SynEditStringRecSize);
  fCapacity := NewCapacity;
end;

{begin}                                                                         //mh 2000-10-19
procedure TSynEditStringList.SetTabWidth(Value: integer);
var
  i: integer;
begin
  if Value <> fTabWidth then begin
    fTabWidth := Value;
    fConvertTabsProc := GetBestConvertTabsProcEx(fTabWidth);
    fIndexOfLongestLine := -1;
{begin}                                                                         //mh 2000-11-08
    for i := 0 to fCount - 1 do
      with fList^[i] do begin
        fExpandedLength := -1;
        Exclude(fFlags, sfHasNoTabs);
        Include(fFlags, sfExpandedLengthUnknown);
      end;
{end}                                                                           //mh 2000-11-08
  end;
end;
{end}                                                                           //mh 2000-10-19

procedure TSynEditStringList.SetUpdateState(Updating: Boolean);
begin
  if Updating then begin
    if Assigned(fOnChanging) then
      fOnChanging(Self);
  end else begin
    if Assigned(fOnChange) then
      fOnChange(Self);
  end;
end;
{end}                                                                           //mh 2000-10-10

{begin}                                                                         //Fiala 2001-12-17
{ InputString is cutted from left side, cuted part is returned as Result}
function TSynEditStringList.WrapString(var InputString: String): String;
const
  WrapableChars = [' ',#9,';','>',','];
var
  i : Integer;
begin
  if not fWordWrap then begin
    Result := InputString;
    InputString := '';
    Exit;
  end;
  if Length(InputString) > fWordWrapWidth then begin
    i := fWordWrapWidth;
    { trying find WrapableChars to the left }
    while i > 0 do begin
      if InputString[i] in WrapableChars
        then Break;
      Dec(i);
    end;
    { on the left is one long word. Try to find on the right side }
    if i = 0 then begin
      i := fWordWrapWidth;
      while i < Length(InputString) do begin
        if InputString[i] in WrapableChars
          then Break;
        Inc(i);
      end;
    end;
  end
  else i:= Length(InputString);
  Result := Copy(InputString, 1, i);
  System.Delete( InputString, 1, i );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -