Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Jul : a non visual component to replace TMemo

www.cryer.info
Managed Newsgroup Archive

a non visual component to replace TMemo

Subject:a non visual component to replace TMemo
Posted by:"Allan Brocklehurst" (bro..@ns.sympatico.ca)
Date:Mon, 10 Jul 2006 15:07:21

Hello;
  well here I go again.

2 parts here.

PART 1:
  My app has to parse out of a record I'm getting from this line  of
code. This part works great
---------------------------------------------
LINE := ReadStringFromFile(Source_Dir + '\' + CURRENT_MEDITECH_FILE);

function TFormMain.ReadStringFromFile(const fileName: string): string;
var
     f: file;
     size: integer;
begin
     assignFile(f, fileName);
     reset(f, 1);
     try
         size := FileSize(f);
         SetLength(result, size);
         BlockRead(f, result[1], size);
     finally
         CloseFile(f);
     end;
end
----------------------------------------
PART 2:
I then assign LINE  to a memo component so I can parse out section based
on know tags <OS>...<OE>, <QS>...<QE>  etc. see function "GetApeice" below.
This works great but it is a visual. I'm using the properties
"SelLEngth","SelStart"  and the  method "GetSelTextBuf" to pick out what
I need.
Question : can I do the same thing using  TStringList or some other non
visual to accomplish the same?  if yes where do I look?

TIA

Allan Brocklehurst

--------------------------------------------------------
         StartString := '<QS>';
         EndString := '<QE>';
         Holdmemo.Text := GetApiece(LINE, StartString, EndString);

function TFormMain.GetApiece(const LINE: string; StartString: string;
EndString: string): string;
var
     S, S1, MemoPart: string;
     FoundStart, FoundEnd: LongInt;
     StartPos, ToEnd: Integer;

     Buffer: PChar;
     Size: Integer;
begin
     Memo_line.Clear;
     linememo.Clear;
     linememo.Lines.Add(LINE);
     linememo.Refresh;
     S := StartString;
     S1 := EndString;
     ToEnd := 0;
     with linememo do
     begin
         { begin the search after the current selection if there is one }
         { otherwise, begin at the start of the text }
         if SelLength <> 0 then

             StartPos := SelStart + SelLength
         else

             StartPos := 0;

         { ToEnd is the length from StartPos to the end of the text in
the rich edit control }

         ToEnd := Length(TEXT) - StartPos;

         FoundStart := FindText(StartString, StartPos, ToEnd,
[stMatchCase]);
         if FoundStart <> -1 then
         begin
             SetFocus;
             SelStart := FoundStart;
             SelLength := Length(S);
         end;

         FoundEnd := FindText(EndString, StartPos, ToEnd, [stMatchCase]);
         if FoundEnd <> -1 then
         begin
             SetFocus;
             SelStart := FoundEnd;
             SelLength := Length(S1);
         end;
     end;
     if FoundStart <> -1 then
     begin
         MemoPart := '';
         Size := ((FoundEnd - 1) - (FoundStart + 4));
         Inc(Size); {Add room for null character}
         GetMem(Buffer, Size); {Creates Buffer dynamic variable}
         linememo.GetSelTextBuf(Buffer, Size);

         MemoPart := StrPas(Buffer);
         linememo.selstart := foundStart + 4;
         linememo.sellength := ((Foundend - 4) - (foundStart + 1));
         MemoPart := '';
         MemoPart := linememo.seltext;
         // here we get rid of the memo area

         linememo.selstart := foundStart;
         linememo.sellength := ((Foundend) - (foundStart - 4));
         linememo.seltext := '';

         FreeMem(Buffer, Size); {Frees memory allocated to Buffer}
     end;
     result := MemoPart;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive