[Lazarus] WriteLn back to the GUI

leledumbo leledumbo_cool at yahoo.co.id
Wed Oct 23 18:30:06 CEST 2013


If I understood correctly, you want to override the meaning of WriteLn (for
programs and units using globals.pas), right? In that case, just create
Write(Ln) procedure in globals unit. That will override the system unit one.
However, you can't have the one with variable number of arguments, at least
not in the system unit style one. Here's a compilable example:

{$mode objfpc} // you have to either in ObjFPC or Delphi mode for array of
const to work

var
  g: Boolean = true; // replace this with your callback variable

procedure WriteLn(args: array of const);
var
  i: Integer;
begin
  if not g then
    System.WriteLn('g') 
  else begin
    for i := Low(args) to High(args) do
      case args[i].vtype of  
        vtinteger    : System.Write(args[i].vinteger);  
        vtboolean    : System.Write(args[i].vboolean);  
        vtchar       : System.Write(args[i].vchar);  
        vtextended   : System.Write(args[i].VExtended^);  
        vtString     : System.Write(args[i].VString^);  
        vtPointer    : System.Write(Longint(args[i].VPointer));  
        vtPChar      : System.Write(args[i].VPChar);  
        vtObject     : System.Write(args[i].VObject.Classname);  
        vtClass      : System.Write(args[i].VClass.Classname);  
        vtAnsiString : System.Write(AnsiString(args[i].VAnsiString));  
        else           System.Write(args[i].vtype);  
      end;  
    System.WriteLn;
  end;
end;

begin
  WriteLn([1]); // yep, you need the angel bracket
  WriteLn([1,2]);
  WriteLn([1,3]);
  WriteLn(['this is ',3,' args']);
end.




--
View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-WriteLn-back-to-the-GUI-tp4033934p4033950.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.




More information about the Lazarus mailing list