Recent

Author Topic: Execute the compiling DOS windows in a memo control.  (Read 8241 times)

vincenzo

  • Newbie
  • Posts: 3
Execute the compiling DOS windows in a memo control.
« on: June 01, 2004, 12:14:05 am »
Well... I'm new here !!
My idea is to insert the content of the DOS compiling windows (where will appear the errors , hints and warnings)into a memo control .
For do that we can get the text buffer from the dos compiling windows(the file lazarus.exe)and put it into a memo control.
The code for do that (in Delphi) is this ...

//Only for win32
procedure LanciaComandoDosInMemo (ComandoDos: String; AMemo:TMemo);
const
    BufferDiLettura = 2400;
var
    AttrSicurezza : TSecurityAttributes;
    CodaDiLettura, CodaDiScrittura : THandle;
    Inizio : TStartUpInfo;
    InfoDelProcesso : TProcessInformation;
    Buffer : Pchar;
    ByteLetti : DWord;
    AppAttiva : DWord;
begin
    with AttrSicurezza do
    begin
        nlength := SizeOf(TSecurityAttributes);
        binherithandle := true;
        lpsecuritydescriptor := nil;
    end;
    if Createpipe (CodaDiLettura, CodaDiScrittura, @AttrSicurezza, 0) then
    begin
        Buffer := AllocMem(32767); // alloca memoria per 32k sostituisci con 65536 per 64k
        FillChar(Inizio, Sizeof(Inizio),#0);
        Inizio.cb := SizeOf(Inizio);
        Inizio.hStdOutput := CodaDiScrittura;
        Inizio.hStdInput := CodaDiLettura;
        Inizio.dwFlags := STARTF_usesTDHANDLES + STARTF_usesHOWWINDOW;
        Inizio.wShowWindow := SW_HIDE;
        if CreateProcess(nil,pchar(comandodos),@AttrSicurezza,@AttrSicurezza,true,
        NORMAL_PRIORITY_CLASS, nil,nil,Inizio,InfoDelProcesso)
        then
        begin
            repeat
            AppAttiva := WaitForSingleObject(InfoDelProcesso.hProcess,100);
            Application.ProcessMessages;
            until (AppAttiva <> WAIT_TIMEOUT);
            Repeat
            ByteLetti := 0;
            ReadFile(CodaDiLettura,Buffer[0], BufferDiLettura,ByteLetti,nil);
            Buffer[ByteLetti]:= #0;
            OemToAnsi(Buffer,Buffer);
            AMemo.Text := AMemo.text + String(Buffer);
            until (ByteLetti < BufferDiLettura);
        end;
        FreeMem(Buffer); // libero la memoria
        CloseHandle(InfoDelProcesso.hProcess);
        CloseHandle(InfoDelProcesso.hThread);
        CloseHandle(CodaDiLettura);
        CloseHandle(CodaDiScrittura);
    end;
end;


with this small portion of this code we can see the contents of an executed dos program into a memo control .

Sorry for my english, but i'm not  english .I'm Italian.

For any questions please reply here or send an e-mail to vincenzodentamaro@hotmail.com

HELLO!!

 

TinyPortal © 2005-2018