[fpc-pascal] Debugging cgi applications

2011-10-28 Thread Ludo Brands
Dear all,

Atached is a small unit that makes debugging cgi applications easier. When
used in a program it will as part of the initialization launch a new process
which opens a terminal (windows:cmd, linux:xterm) and starts gdb attaching
to the calling proces. A short sleep makes sure gdb breaks the program
while still initializing. It has been tested on windows xp32 with apache 2.2
running as an application or as a service and on ubuntu 10.04 64 with apache
2.2. 
Further instructions are in the unit.

I've also tested this unit sucessfully in a windows library. It helps
debugging of dll's where the Host Application method fails. 

Ludo
unit SelfDebug;

{
Instructions:
-Include unit anyware in the program.
-Change DEBUGGER constant to match your debugger
-For Windows, if the program to debug is running as a service (fe. CGI 
application
 from apache running as a service), make sure the service is configured with
 Interact with desktop checked. Failing to do so, the debugger will be started
 without a console, break the program and hang waiting for input. Killing the 
debugger
 is your only option.
-For Linux, if the program to debug is running as a different user (fe. CGI 
application),
 run xhost + in a terminal to enable all users to connect to xserver.
 If needed, change DISPLAY to match your DISPLAY environment variable
}

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils,Process;

implementation

const
  {$ifdef windows}
  DEBUGGER='C:\lazarus\mingw\bin\7.3\gdb.exe';
  {$endif}
  {$ifdef linux}
  DEBUGGER='gdb';
  DISPLAY=':0.0';
  {$endif}
  MSWAIT=2000;

var
  AProcess: TProcess;

initialization
AProcess := TProcess.Create(nil);
{$ifdef windows}
AProcess.CommandLine := format('cmd /C START Debugging %s /WAIT %s %s 
%d',[paramstr(0),debugger,paramstr(0),GetProcessID]);
{$endif}
{$ifdef linux}
AProcess.CommandLine := format('xterm -display %s -T Debugging %s -e %s 
%s %d',[DISPLAY,paramstr(0),DEBUGGER,paramstr(0),GetProcessID]);
{$endif}
AProcess.Execute;
sleep(MSWAIT);
finalization
AProcess.Free;
end.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] XML - How to set and use a Namespace Prefix?

2011-10-28 Thread Daniel Gaspary
I'm trying to create an XML Document with multiple Namespaces.

With the code below[1] a get as result the following XML:

svg xmlns=http://www.w3.org/2000/svg; /

How can I set a second Namespace, should I use SetAttribute or
SetAttributeNS ? :

root.setattribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');

?

Can anybody give me an example when setAttributeNS is useful ?

Is there a way to, after setting a namespace prefix, make all
attributes and elements to be added using it ?

Thanks


[1]
var
   Doc: TXMLDocument;
   root, node: TDOMElement;
begin
 Doc:=TXMLDocument.Create;

 root:=Doc.CreateElementNS('http://www.w3.org/2000/svg', 'svg');
 Doc.AppendChild(root);
...
end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal