Archive

Archive for the ‘Delphi’ Category

Did you say Indy?!

February 2nd, 2008

Indy version 10. Must hold the title for world’s most unfriendly Delphi/comms help files and documentation! Thanks to Google (and RenĂ© Laursen from TeamB), I’ve been able to code-up some TCP comms in a few hours which otherwise might have taken a few days. But, thanks Indy! Those components are truly great.

http://www.indyproject.org/

Delphi ,

Sample function for reading XML node value

January 2nd, 2008

I’ve had many problems using the IXMLDocument object, mostly related to different versions of the .net redistributable installed on different machines. So, I wrote a short function that extracts a node value from the passed XML string:

function GetNodeVal(sNode, sXML : string) : string ;
{This function extracts the specified xml node's value from the XML string}

var
  iPos : integer ;
  sValue : string ;

begin
  iPos := Pos('<'+ sNode + '>', sXML) ;

  if iPos = 0 then
  begin
    iPos := Pos('<'+ Lowercase(sNode) + '>', sXML) ;

    if iPos = 0 then
    begin
      result := 'Error:Globals.GetNodeVal' ;
      exit ;
    end;
  end;

  sValue := Copy(sXML, iPos + 2 + Length(sNode), 255) ;

  iPos := Pos('</' + sNode + '>', sValue) ;

  if iPos = 0 then
  begin
    iPos := Pos('</'+ Lowercase(sNode) + '>', sValue) ;

    if iPos = 0 then
    begin
      result := 'Error:Globals.GetNodeVal' ;
      exit ;
    end;
  end;

  sValue := Copy(sValue, 1, iPos -1) ;
  result := sValue ;
end;

Delphi