[Lazarus] WriteLn back to the GUI

ListMember listmember at letterboxes.org
Wed Oct 23 23:08:51 CEST 2013


On 2013-10-23 22:36, Sven Barth wrote:
> I've attached my own version of EditText which I just adjusted. It 
> works very similar to the original version I linked, but allows to use 
> any TCustomEdit descendant (TMemo is one of them).
>

Thank you.

But, I am still getting "exception class: 'External: SIGSEGV'" in here:

function EditWrite(var F: TTextRec): Integer; far;
begin
   with F do
   begin
     BufPtr^[BufPos] := #0;
PEditData(@F.UserData)^.Edit.SetSelTextBuf(PChar(BufPtr)); { <-- Here }
     BufPos := 0;
   end;
   EditWrite := 0;
end;

>> But, why would I have to write 100+ lines of code just to capture the
>> output of WriteLn.
>>
>> Plus, I keep getting segfaults when I close the application --something
>> is calling InOutFunc when the app closes and still tries to write to a
>> destroyed TMemo.
>
> You'll need to store the old value of "Output" and restore that before 
> your form is destroyed.

I tried it, but doesn't seem to work.

Here is the exact code I am using your modified code:

procedure TForm1.Button1Click(Sender: TObject);
begin
   try
     AssignEdit(System.Input, Memo1);
     Reset(System.Input);

     AssignEdit(System.Output, Memo2);
     Rewrite(System.Output);

     try
       DoPPExecute;
     except
       on E: Exception do begin
         Sleep(0);
       end;
     end;
   finally
     //CloseFile(System.Input);
     //CloseFile(System.Output);
   end;
end;

Uncommenting the closefile() stuff doesn't make any difference.

>> I think I'll go with Leledumbo's solution --and yes, will alter the
>> globals.pas in the compiler's source.
>
> Adding a callback to globals.pas will be the completely wrong way... 

I hear you, loud and clear :)

But, hearing you say that, doesn't mean I understand why it is so 
--especially when it does not help me :)

Could you please elaborate a little why it would the completely wrong way?

[this is from your other email in this thread]

> Let's maybe get a few things straight first: what are you trying to 
> achieve in the end? Do you want to capture FPC's output or do you want 
> to redirect the console output of your own application?
> If the first: Why don't you simply use the functionality of the OS to 
> redirect the output to a file? Or do you start FPC from within your 
> own application? In that case you could use the pipe mechanism of e.g. 
> TProcess to capture the output (Lazarus does it the same way).

Here is what I have done:

I have copied all the stuff in the 'compiler' folder somewhere else and 
altered the pp.lpi into pp.pas and made it part of my DemoProject.lpi.

I have renamed the main proc in pp.lpi to be DoPPExecute.

It builds and compiles fine.

It also runs, sort of fine.

Except that, those WriteLn stuff doesn't because it's no more a console app.

This is the point I need to solve that WriteLn headache.

Honestly, I was preapred for any other issue, but I never expected 
WriteLn to such a sacred cow that I need to perform such elaborate 
rituals to workaround it --even then it doesn't seem to work so far.




More information about the Lazarus mailing list