Board index » delphi » String Grid - How to load a null terminated string

String Grid - How to load a null terminated string

I can load a delimited null terminated string in to a TMemo using
SetTextBuf.

Is it possible to load the cells of a string grid in the same manner?

My string looks like this

Date<TAB>19960712<CR><LF>Time<TAB>12:00<CR><LF><$0>

I want the string grid to look like this

Date      19960712
Time      12:00

Any help would be much appreciated.

Regards

Steve White
University of Warwick
Coventry, UK

 

Re:String Grid - How to load a null terminated string


Steve White wrote :  

Quote
> I can load a delimited null terminated string in to a TMemo using
> SetTextBuf.

> Is it possible to load the cells of a string grid in the same manner?

> My string looks like this

> Date<TAB>19960712<CR><LF>Time<TAB>12:00<CR><LF><$0>

> I want the string grid to look like this

> Date      19960712
> Time      12:00

> Any help would be much appreciated.

> Regards

> Steve White
> University of Warwick
> Coventry, UK

I wrote this code to paste data into a grid copied to the clipboard from Excel.
A few modifications might be needed to make it fit your needs :

procedure TEntryForm.EditPasteClick(Sender: TObject);
var
  Hnd : THandle;
  n, ACol, ARow : longint;
  ClipData, Buff: PChar;
  Ch : char;
  S : string;
const
  MaxSize = 65526;
begin
  if not Clipboard.HasFormat(CF_TEXT) then Exit;
  Buff := StrAlloc(MaxSize);
  try
    Hnd := Clipboard.GetAsHandle(CF_TEXT);
    ClipData := GlobalLock(Hnd);
    StrCopy(Buff, ClipData);
    GlobalUnlock(Hnd);
    n := 0;
    S := '';
    ACol := sgEntryGrid.Selection.Left;
    ARow := sgEntryGrid.Selection.Top;
    repeat
      Ch := Buff[n];
      case Ch of
        #9 : begin
               sgEntryGrid.Cells[ACol, ARow] := S;
               S := '';
               ACol := ACol + 1;
             end;
        #13: begin
               sgEntryGrid.Cells[ACol, ARow] := S;
               S := '';
               ARow := ARow + 1;
               ACol := sgAbstr.Selection.Left;
             end;
        #0, #10 : ;
        else S := S + Ch;
      end;
      n := n + 1;
    until (Ch = #0) or (n >= MaxSize);
  finally StrDispose(Buff);
  end;
end;

Greg Mockler
greg...@iafrica.com

Other Threads