Re: [fpc-pascal] Javascript in Desktop Applications

2011-02-07 Thread Brian Winfrey
On Mon, Feb 7, 2011 at 6:27 AM,  michael.vancann...@wisa.be wrote:


 On Mon, 7 Feb 2011, Andrew Brunner wrote:

 On Mon, Feb 7, 2011 at 7:35 AM,  michael.vancann...@wisa.be wrote:

 A cross-platform solution is to use one of libsee or BESEN.

 The latter is implemented in 100% native Object Pascal.

 Michael.

 BESEN is very, very, very  well written but I can't seem to get any
 indication how to use it in my project.  I would love FPC to include a
 JIT system for JS or Pascal.  IMO, FPC absolutely needs a scripting
 FCL going forward.  BESEN seems like the right guy for the job, but I
 suspect he's burned out :-(  I think he had memory concerns too.


 Does anyone have any BESEN examples that integrated actual FPC units?
 It seems like all the samle js units are self contained with no
 interface to system or GUI units.


 Including JS support on my project would enable people to leverage
 exiting proven technologies which would make for easier/allowable
 for adoption in working groups / houses where selection of language is
 restricted to language of the day :-)  Taking this statment and
 applying this across the board, it would be an easier sell for
 adoption of FPC/Lazarus with JIT support.  Personally, I'm thinking
 along the lines of Web RAD down the road...

 Well, if you can't get BESEN to work, libsee definitely does.
 I even have an article on how to do it.

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


I have some interest in exploring javascript implementations for fpc.
http://code.google.com/p/fpcjs/  -- Is this comparable to what you have noted?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Win32 Application Query.

2011-01-31 Thread Brian Winfrey
On Sun, Jan 23, 2011 at 2:25 AM, Justin Smyth
delph...@smythconsulting.net wrote:
 Hi guys

 I've been working on a application to application communications protocol
 via named pipes.

 the basic idea would be for Application A to change a Component Property on
 Applications B ( ie the visible property) or a text or caption or width /
 height of a component. ( and also for Application to cause and event to fire
 on application b only , ie a screen refresh or data change event ie reset a
 label to its primary state )

 I'm also going to allow application A to change Applications B event
 handlers ie onClick onEnter OnKeyPress etc so that Application A can
 redirect an event handler so that when an event is triggered on Application
 B

 My Question is does any components out there like fpGUI do this ?


 once i am done and its working i'd be happy to share the code , at present i
 can change component values and read them from the remote end.

 Kind Regards


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


I think you may find what you're looking for in MSE project's IFI?
components.  Google MSEGUI to find it.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] JSON - RTTI streaming.

2011-01-20 Thread Brian Winfrey
On Wed, Jan 5, 2011 at 3:12 PM, Michael Van Canneyt
mich...@freepascal.org wrote:
 Hello,

 For those of you that need JSON support:

 I have committed support for streaming published properties (properties for
 which RTTI  is generated) from objects to JSON and vice versa, in a unit
 fpjsonrtti.

 Not the full streaming as implemented in the classes system is supported:
 - No DefineProperties.
 - No methods.
 Although it should not be difficult to add support for this.

 In contrast, it can stream simple collections and stringlists (with ojects
 attached) in various ways.
 There are various events to influence the streaming process.
 This should be more than enough to stream objects to and from a web-browser.

 I have committed an example and a testsuite.
 All this is in packages/fcl-json.

 Despite the fact that the testsuite runs OK , I'd like to ask those for whom
 it might be useful to test the code and report any errors you find to me.
 Suggestions for improvements are also welcome.

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


Nice, this was on my to do list.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Cannot get TFPTimer to work

2010-12-02 Thread Brian Winfrey
See .../fpcsrc/packages/fcl-base/examples/testtimer.pp for example usage.


On Thu, Dec 2, 2010 at 10:39 AM, Darius Blaszyk
dhkblas...@zeelandnet.nl wrote:
 Whatever I tried, I cannot get TFPTimer to work. Can someone help? For
 some reason the OnTimer even is never fired. Tried on Windows and Linux.
 Here's a snippet I used as test.

 Regards, Darius



 program fptimertest;

 {$mode objfpc}{$H+}

 uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils, fpTimer;

 type

  { TBaseObj }

  TBaseObj = class(TObject)
     tmr: TFPTimer;
  public
     constructor Create;
     constructor Destroy;
     procedure OnTimerExec(Sender: TObject);
  end;

 { TBaseObj }

 constructor TBaseObj.Create;
 begin
  tmr := TFPTimer.Create(nil);
  tmr.Interval := 1;
  tmr.OnTimer:=...@ontimerexec;
  tmr.StartTimer;
 end;

 constructor TBaseObj.Destroy;
 begin
  tmr.StopTimer;
  tmr.Free;
 end;

 procedure TBaseObj.OnTimerExec(Sender: TObject);
 begin
  writeln('Timer executed');
 end;

 var
  test: TBaseObj;
  i: integer;

 begin
  test := TBaseObj.Create;
  for i := 1 to 1000 do
    sleep(10);

  writeln('done');
  readln;
 end.

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

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


Re: [fpc-pascal] make fpc

2010-11-22 Thread Brian Winfrey
On Mon, Nov 22, 2010 at 1:48 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote:

 On 21 Nov 2010, at 19:03, Brian Winfrey wrote:

 What version should fpc display (Revision: 16393).

 When I get latest and make /usr/bin/fpc is at version 2.4.2.

 fpc -vut dummy.pas
 ...
 Compiler: /usr/lib/fpc/2.4.2/ppc386
 Using executable path: /usr/lib/fpc/2.4.2/
 Using unit path: /usr/lib/fpc/2.4.2/units/i386-linux/rtl/
 ...

 The output indicates that 2.4.3 directories are created and 2.4.3
 compiler is used.

 I run
  make clean build  make install INSTALL_PREFIX=/usr

 There are two separate things: the installed FPC versions, and the default
 FPC version. The default FPC version is determined by the symbolic links
 /usr/bin/ppc386, /usr/bin/ppcx64 etc (or /usr/local/bin/ppc386 etc on
 non-Linux). A make install will add a new FPC version, but it does not
 make it the default. If you want to do that, change the symlinks to point to
 the new compiler version. The fpc utility is only a wrapper that calls
 through to ppc386/ppcx64/... and has no version itself.


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


I thought there was a sym link involved, but I mis-remembered it being
fpc.  That clears it up thanks.

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


[fpc-pascal] Re: make fpc

2010-11-21 Thread Brian Winfrey
I also tried make cycle as outlined in programmers guide, but
results are the same.

On Sun, Nov 21, 2010 at 10:03 AM, Brian Winfrey bwcod...@gmail.com wrote:
 What version should fpc display (Revision: 16393).

 When I get latest and make /usr/bin/fpc is at version 2.4.2.

 fpc -vut dummy.pas
 ...
 Compiler: /usr/lib/fpc/2.4.2/ppc386
 Using executable path: /usr/lib/fpc/2.4.2/
 Using unit path: /usr/lib/fpc/2.4.2/units/i386-linux/rtl/
 ...

 The output indicates that 2.4.3 directories are created and 2.4.3
 compiler is used.

 I run
  make clean build  make install INSTALL_PREFIX=/usr

 I also tried
  make clean FPC=/usr/lib/fpc/2.4.3/ppc386 build.

 The output of make install is attached.

 Is this wrong?

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


Re: [fpc-pascal] TReader.ReadProperty

2010-11-04 Thread Brian Winfrey
See post from about two weeks ago. Building FPC with debug information

On Wed, Nov 3, 2010 at 3:39 AM, Roland Turčan - RoTurSoft
i...@rotursoft.sk wrote:


 On Wed, Nov 3, 2010 at 9:17 AM, Michael Van Canneyt mich...@freepascal.org
 wrote:

 PS: How can I debug TReader class, because debuger steps over my calls
 from
 TReader.

 You must recompile the RTL with debug information, and then recompile your
 project.


 Thanks for answer, but please could you assist me how to build RTL with
 debug infos.

 Thanks.


 --
 Best regards, TRoland
 http://www.rotursoft.sk

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

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


Re: [fpc-pascal] MSEide+MSEgui rev.2.4

2010-11-02 Thread Brian Winfrey

 The fixes_2_4 is already at version 2.4.3 and contains everything from
 2.4.2 and more...

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


Re: [fpc-pascal] MSEide+MSEgui rev.2.4

2010-11-01 Thread Brian Winfrey
Which address should I be using?  It looks like the UUID and revision
are the same while Last changed revision and path are different.

svn info http://svn.freepascal.org/svn/fpc/tags/release_2_4_2
Path: release_2_4_2
URL: http://svn.freepascal.org/svn/fpc/tags/release_2_4_2
Repository Root: http://svn.freepascal.org/svn/fpc
Repository UUID: 3ad0048d-3df7-0310-abae-a5850022a9f2
Revision: 16285
Node Kind: directory
Last Changed Author: marco
Last Changed Rev: 16278
Last Changed Date: 2010-10-31 10:08:18 -0700 (Sun, 31 Oct 2010)

svn info http://svn.freepascal.org/svn/fpc/branches/fixes_2_4
Path: fixes_2_4
URL: http://svn.freepascal.org/svn/fpc/branches/fixes_2_4
Repository Root: http://svn.freepascal.org/svn/fpc
Repository UUID: 3ad0048d-3df7-0310-abae-a5850022a9f2
Revision: 16285
Node Kind: directory
Last Changed Author: marco
Last Changed Rev: 16277
Last Changed Date: 2010-10-31 10:01:50 -0700 (Sun, 31 Oct 2010)



On Mon, Nov 1, 2010 at 7:14 AM, Graeme Geldenhuys
graemeg.li...@gmail.com wrote:
 Op 2010-11-01 15:48, Marcos Douglas het geskryf:
 If you use the FPC from
 http://svn.freepascal.org/svn/fpc/branches/fixes_2_4 then the version
 is 2.4.3, right?

 Yes, and that works with MSEide too.



 Regards,
  - Graeme -

 --
 fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
 http://opensoft.homeip.net:8080/fpgui/

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

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


Re: [fpc-pascal] Re: Re: TPLY

2010-10-29 Thread Brian Winfrey
Well, seems like you all have given some material to get me started.
As nobody suggested sticking with TPLY or plex/bison I will
back-burner that and proceed with crenshaw/oberon.

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


Re: [fpc-pascal] TPLY

2010-10-29 Thread Brian Winfrey
Thanks, I'll look into this as well.

On Fri, Oct 29, 2010 at 2:19 AM, Thierry Coq t...@free.fr wrote:
 Brian,
 thanks for the diff, I'll take it into account and publish an update.

 On 28/10/2010 18:50, Brian Winfrey wrote:
 ...

 The changes I made in this diff were simply to get it to compile.

 Subsequently I renamed all files and folders to lowercase, converted
 spaces to underscores and added a prefix to eliminate duplicate file
 names where needed.



 ...

 Another approach would be to look at (and reverse engineer) the byte
 code.
 If it's not obfuscated, it might even be easier to parse and port than
 the
 native Java.



 How would you suggest I proceed in that.


 Using the class file format (for example here:
 http://en.wikipedia.org/wiki/Class_%28file_format%29),
 it would be easy to parse through the tables, identify the class name, its
 super class name, the interfaces it's implementing, and even the public and
 private methods. The java compiler has done all the work into translating
 the java code into nice tables. ;-)
 I remember I did the exercise once. I've destroyed the code, but I could do
 it again. I remember one of the more difficult parts was understanding how
 java coded strings ;-) This was before anonymous classes and methods, so
 this could be another difficulty. I don't know how these are converted to
 byte code.
 Once you have the structure, you can generate the pascal code. I would
 recommend against generating one class per unit as Java does: since pascal
 dependency rules are strict (no cycles), this would most certainly result in
 uncompilable code. What I do when I translate Java is to pre-declare all
 classes and interfaces at the top of the unit(s) and then generate the full
 class interface further down.
 Translating the statements inside the bytecode I haven't tried, since my
 efforts were mostly for analyzing java code and measuring it.
 I hope this helps,
 Thierry

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

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


Re: [fpc-pascal] Re: TPLY

2010-10-28 Thread Brian Winfrey
Thank you, What techiniques have you used in the past that you could
share to get me started?

On Wed, Oct 27, 2010 at 8:04 PM, leledumbo leledumbo_c...@yahoo.co.id wrote:

 Learn compilation technique, a recursive descent parser should be easy to
 understand and code instead of learning automatic lexer and parser
 generator. Plus, structurally, Java is a very simple language, so AST
 transformation should be easy. With FPC 2.5.1, almost all Java constructs
 can be directly translated to FPC dialect, minus anonymous inner class only
 AFAIK.
 --
 View this message in context: 
 http://free-pascal-general.1045716.n5.nabble.com/TPLY-tp3235828p3239905.html
 Sent from the Free Pascal - General mailing list archive at Nabble.com.
 ___
 fpc-pascal maillist  -  fpc-pas...@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-pascal

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


[fpc-pascal] TPLY

2010-10-25 Thread Brian Winfrey
I recently saw a semi working example of a Java to Delphi converter
that was done with javacc.  Unfortunately it would only convert simple
java (v 1.4 maybe).

Can anyone recommend a good place to start reading or offer any advise
to accomplish this with TPLY.

I am looking into porting some Java libraries to FPC 2.5.x, and am
unfamiliar with the TPLY tools.

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


Re: [fpc-pascal] Building FPC with debug information

2010-10-20 Thread Brian Winfrey
 make OPT=-O- DEBUG=1 all

When I ran this I see that both -dDEBUG and -dRELEASE are passed on
the fpc command line.  Is that correct?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] IntList

2010-10-19 Thread Brian Winfrey
Take a look at http://code.google.com/p/fprb/.  I have just perused
it, but it looks pretty good.

Brian.


 Currently, the FPC team is looking at an implementation of Vlado Boza
 us...@ksp.sk for a standard template library for inclusion in FPC.

 The code is on

 http://code.google.com/p/stlpascal

 Please have a look and comment on it.

 I'm not a generics expert and am not in the position to judge whether this
 library is good or not.

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

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


Re: [fpc-pascal] What are the issues involved in threads sharing variables?

2010-10-19 Thread Brian Winfrey
 Polling where the list size is highly dynamic you will need protect
 it.  I think FPC has thread safe list objects too.

Yes it does, Classes.TThreadList I think.  I thought it was a
conatiner for threads, but it is a safe list.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] lNet getting the local IP

2010-10-08 Thread Brian Winfrey

 I didn't try it, but I see that it tries to connect to google's dns serve=
r,
 so it'd fail miserably if the computer has no internet access.

 Bye
 --
 Luca


I tested, without web access does not work. :o
A hard coded address will of course fail if it cannot be reached.
The code was an example, you should use it as such.  I substituted my 
router's ip for google's and it works.;)

Choose a different address that would not fail in a specific
situation.   

As another example, one could read their /etc/resolve file to get
the dns server that is assigned.  

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


Re: [fpc-pascal] lNet getting the local IP

2010-10-07 Thread Brian Winfrey
 On 06/10/10 14:27, Felipe Monteiro de Carvalho wrote:
 Ok, thanks everyone, it seams that I managed to extract a function
 from Silvio's code which doesn't use Synapse. I only tested in Windows
 so far:

 unit chesstcputils;

 {$mode objfpc}{$H+}

 interface

 uses
    {$IFDEF MSWINDOWS}
    Winsock,
    {$ENDIF}
    Classes, SysUtils;

 function ChessGetLocalIP(): string;

 implementation

 const
    CFormatIPMask = '%d.%d.%d.%d';

 function ChessGetLocalIP(): string;
 var
    I, VAttempt: Integer;
    VStrTemp, VSitesToTry: TStringList;
 {$IFDEF UNIX}
    VProcess: TProcess;
 {$ENDIF}
 {$IFDEF MSWINDOWS}
 var
    VWSAData: TWSAData;
    VHostEnt: PHostEnt;
    VName: string;
 {$ENDIF}
 begin
    Result := '';
 {$IFDEF UNIX}
        VStrTemp := TStringList.Create;
        VProcess := TProcess.Create(nil);
        try
          VProcess.CommandLine :=
            'sh -c ifconfig eth0 | awk ''/inet end/ {print $3}''';

 Yuck.  This doesn't work on my system (debian).  If you really want the
 least effort, you may have more luck with simply parsing `hostname -I`
 somehow.  The right way to do this is with an ioctl, I believe
 (SIOCGIFCONF).  Look here:

 http://www.kernel.org/doc/man-pages/online/pages/man7/netdevice.7.html

 I'm sure there's some code floating around, but it probably means that
 you have to translate some headers :(.

 Henry

 Re: [fpc-pascal] lNet getting the local IP


 I found an example for linux on stack overflow that was in c
 http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-computer

 - here is a rough translation:

 program GetPrimaryIpAddress;
 {$mode objfpc}

 uses
  baseunix,
  unixtype,
  sockets,
  SysUtils;

 procedure Get(var buf: array of char; const len: longint);
 const
  CN_GDNS_ADDR = '8.8.8.8';
  CN_GDNS_PORT = 53;
 var
  s: string;
  sock: longint;
  err: longint;
  HostAddr: TSockAddr;
  l: Integer;
  UnixAddr: TInetSockAddr;

 begin
  err := 0;
  Assert(len = 16);

  sock := fpsocket(AF_INET, SOCK_DGRAM, 0);
  assert(sock  -1);

  UnixAddr.family := AF_INET;
  UnixAddr.port := htons(CN_GDNS_PORT);
  UnixAddr.addr := StrToHostAddr(CN_GDNS_ADDR).s_addr;

  if (fpConnect(sock,@UnixAddr,SizeOf(UnixAddr)) = 0) then
  begin
    try
      l := SizeOf(HostAddr);
      if (fpgetsockname(sock, @HostAddr, @l) = 0) then
      begin
        s := NetAddrToStr(HostAddr.sin_addr);
        StrPCopy(PChar(Buf), s);
      end
      else
      begin
        err:=socketError;
      end;
    finally
      if (fpclose(sock)  0) then
      begin
        err := socketError;
      end;
    end;
  end
  else
  begin
    err:=socketError;
  end;

  if (err  0) then
  begin
    // report error
  end;
 end;

 var
  ipbuf: array[0..255] of char;

 begin
  system.FillChar(ipbuf, sizeOf(ipBuf), #0);
  Get(ipbuf, system.SizeOf(ipbuf));
  WriteLn(StrPas(ipbuf));
 end.

 BrianW

I have tried this code with multiple scenarios.

if interfaces are down, no ip address is returned. I would say that is
expected as there is no network.
ifconfig will return same. only lo has an address 127.0.0.1.

Otherwise I get the primary ip address as long as routing is used.

if connecting to 0.0.0.0, 127.0.0.1 is returned

Use 127.0.0.1 and the primary is returned.

Run some tests and let me know what you find.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] lNet getting the local IP

2010-10-07 Thread Brian Winfrey
I think you want to use 127.0.0.1 to return the actual address.

In my case I would

const
  CN_GDNS_ADDR = '127.0.0.1';

run the progarm and the output would be 192.168.1.5 as long as there
is an active interface.

On Thu, Oct 7, 2010 at 3:34 PM, silvioprog silviop...@gmail.com wrote:
 Hi Brian,
 I tested again, and discovered that's not is necessary a connection to a
 web.
 I changed to 0.0.0.0 and returned 127.0.0.1, perfect! :)
 I will use this function. Thanks very much again. :)
 2010/10/7 Brian Winfrey bwcod...@gmail.com

  On 06/10/10 14:27, Felipe Monteiro de Carvalho wrote:
  Ok, thanks everyone, it seams that I managed to extract a function
  from Silvio's code which doesn't use Synapse. I only tested in Windows
  so far:
 
  unit chesstcputils;
 
  {$mode objfpc}{$H+}
 
  interface
 
  uses
     {$IFDEF MSWINDOWS}
     Winsock,
     {$ENDIF}
     Classes, SysUtils;
 
  function ChessGetLocalIP(): string;
 
  implementation
 
  const
     CFormatIPMask = '%d.%d.%d.%d';
 
  function ChessGetLocalIP(): string;
  var
     I, VAttempt: Integer;
     VStrTemp, VSitesToTry: TStringList;
  {$IFDEF UNIX}
     VProcess: TProcess;
  {$ENDIF}
  {$IFDEF MSWINDOWS}
  var
     VWSAData: TWSAData;
     VHostEnt: PHostEnt;
     VName: string;
  {$ENDIF}
  begin
     Result := '';
  {$IFDEF UNIX}
         VStrTemp := TStringList.Create;
         VProcess := TProcess.Create(nil);
         try
           VProcess.CommandLine :=
             'sh -c ifconfig eth0 | awk ''/inet end/ {print $3}''';
 
  Yuck.  This doesn't work on my system (debian).  If you really want the
  least effort, you may have more luck with simply parsing `hostname -I`
  somehow.  The right way to do this is with an ioctl, I believe
  (SIOCGIFCONF).  Look here:
 
  http://www.kernel.org/doc/man-pages/online/pages/man7/netdevice.7.html
 
  I'm sure there's some code floating around, but it probably means that
  you have to translate some headers :(.
 
  Henry
 
  Re: [fpc-pascal] lNet getting the local IP
 
 
  I found an example for linux on stack overflow that was in c
 
  http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-computer
 
  - here is a rough translation:
 
  program GetPrimaryIpAddress;
  {$mode objfpc}
 
  uses
   baseunix,
   unixtype,
   sockets,
   SysUtils;
 
  procedure Get(var buf: array of char; const len: longint);
  const
   CN_GDNS_ADDR = '8.8.8.8';
   CN_GDNS_PORT = 53;
  var
   s: string;
   sock: longint;
   err: longint;
   HostAddr: TSockAddr;
   l: Integer;
   UnixAddr: TInetSockAddr;
 
  begin
   err := 0;
   Assert(len = 16);
 
   sock := fpsocket(AF_INET, SOCK_DGRAM, 0);
   assert(sock  -1);
 
   UnixAddr.family := AF_INET;
   UnixAddr.port := htons(CN_GDNS_PORT);
   UnixAddr.addr := StrToHostAddr(CN_GDNS_ADDR).s_addr;
 
   if (fpConnect(sock,@UnixAddr,SizeOf(UnixAddr)) = 0) then
   begin
     try
       l := SizeOf(HostAddr);
       if (fpgetsockname(sock, @HostAddr, @l) = 0) then
       begin
         s := NetAddrToStr(HostAddr.sin_addr);
         StrPCopy(PChar(Buf), s);
       end
       else
       begin
         err:=socketError;
       end;
     finally
       if (fpclose(sock)  0) then
       begin
         err := socketError;
       end;
     end;
   end
   else
   begin
     err:=socketError;
   end;
 
   if (err  0) then
   begin
     // report error
   end;
  end;
 
  var
   ipbuf: array[0..255] of char;
 
  begin
   system.FillChar(ipbuf, sizeOf(ipBuf), #0);
   Get(ipbuf, system.SizeOf(ipbuf));
   WriteLn(StrPas(ipbuf));
  end.
 
  BrianW
 
 I have tried this code with multiple scenarios.

 if interfaces are down, no ip address is returned. I would say that is
 expected as there is no network.
 ifconfig will return same. only lo has an address 127.0.0.1.

 Otherwise I get the primary ip address as long as routing is used.

 if connecting to 0.0.0.0, 127.0.0.1 is returned

 Use 127.0.0.1 and the primary is returned.

 Run some tests and let me know what you find.

 --
 Silvio Clécio,
 programmer ObjectPascal


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

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


Re: [fpc-pascal] lNet getting the local IP

2010-10-07 Thread Brian Winfrey
I don't know if you noticed, but it appears that code has some
depracated properties that should be changed.

Here are the modifications I made in exploring this issue:

program GetPrimaryIpAddress;
{$mode objfpc}

uses
  baseunix,
  unixtype,
  sockets,
  SysUtils;

procedure Get(out AddrOut: string);
const
  CN_GDNS_ADDR = '127.0.0.1';
  CN_GDNS_PORT = 53;
var
  sock: longint;
  err: longint;
  UnixAddr: TInetSockAddr;
  HostAddr: TSockAddr;
  len: Integer;
begin
  err := 0;

  sock := fpsocket(AF_INET, SOCK_DGRAM, 0);
  assert(sock  -1);

// changed because previous properties were deprecated
  UnixAddr.sin_family := AF_INET;
  UnixAddr.sin_port := htons(CN_GDNS_PORT);
  UnixAddr.sin_addr := StrToHostAddr(CN_GDNS_ADDR);

  if (fpConnect(sock, @UnixAddr, SizeOf(UnixAddr)) = 0) then
  begin
try
  len := SizeOf(HostAddr);
  if (fpgetsockname(sock, @HostAddr, @len) = 0) then
  begin
AddrOut := NetAddrToStr(HostAddr.sin_addr);
  end
  else
  begin
err:=socketError;
  end;
finally
  if (fpclose(sock)  0) then
  begin
err := socketError;
  end;
end;
  end
  else
  begin
err:=socketError;
  end;

  if (err  0) then
  begin
// report error
  end;
end;

var
  strAddr: string;

begin
  Get(strAddr);
  WriteLn('ip : ',strAddr);
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] lNet getting the local IP

2010-10-06 Thread Brian Winfrey
On Wed, Oct 6, 2010 at 7:09 AM,
fpc-pascal-requ...@lists.freepascal.org wrote:
 Send fpc-pascal mailing list submissions to
        fpc-pas...@lists.freepascal.org

 To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.freepascal.org/mailman/listinfo/fpc-pascal
 or, via email, send a message with subject or body 'help' to
        fpc-pascal-requ...@lists.freepascal.org

 You can reach the person managing the list at
        fpc-pascal-ow...@lists.freepascal.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of fpc-pascal digest...


 Today's Topics:

   1. Re:  GetTempFileName in Linux (Michael Van Canneyt)
   2. Re:  GetTempFileName in Linux (Jonas Maebe)
   3. Re:  lNet getting the local IP (Andrew Brunner)
   4. Re:  lNet getting the local IP (Sven Barth)
   5. Re:  lNet getting the local IP (Felipe Monteiro de Carvalho)
   6. Re:  lNet getting the local IP (Andrew Brunner)
   7. Re:  lNet getting the local IP (Marco van de Voort)
   8. Re:  lNet getting the local IP (Henry Vermaak)


 --

 Message: 1
 Date: Wed, 6 Oct 2010 11:59:53 +0200 (CEST)
 From: Michael Van Canneyt mich...@freepascal.org
 Subject: Re: [fpc-pascal] GetTempFileName in Linux
 To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
 Message-ID: alpine.deb.2.00.1010061158450.6...@fsb.wals.be
 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed



 On Wed, 6 Oct 2010, Jonas Maebe wrote:


 On 06 Oct 2010, at 11:05, Michael Van Canneyt wrote:

 On Wed, 6 Oct 2010, Jonas Maebe wrote:

 On 06 Oct 2010, at 09:41, Michael Van Canneyt wrote:

 This is always true on Unix, the only way to make sure is to have the
 kernel
 create the temporary name and file for you. Unix - to my knowledge - does
 not have a way to create and lock a file in one atomic operation; There
 are
 always 2 operations involved, and so anything can happen between the 2
 calls.

 You can at least open a file with O_CREAT|O_EXCL|O_NOFOLLOW to make sure
 that it does not yet exist at the point that you create it (and that it's
 not a symlink either).

 This is correct, but doesn't lock the file,

 Locking is always advisory on Unix, so that doesn't matter anyway.

 and so it doesn't prevent
 someone from 'stealing' the file before the lock is applied.

 Nobody else can steal the file once you have created it, because they won't
 be the owner nor have the necessary permissions. That is the main security
 risk and it is solved by this approach. The fact that another process running
 under your login not using O_EXCL could overwrite it is not an extra security
 risk (if you have a rogue process running under your login, nothing that you
 do is safe because it can use ptrace to modify any process in any way it sees
 fit anyway).

 And that is why I think the whole point is hugely exaggerated :-)

 But it doesn't mean we shouldn't do our best to make it minimally safe.

 Michael.


 --

 Message: 2
 Date: Wed, 6 Oct 2010 12:57:02 +0200
 From: Jonas Maebe jonas.ma...@elis.ugent.be
 Subject: Re: [fpc-pascal] GetTempFileName in Linux
 To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
 Message-ID: 6cd7d25a-fd10-4c7d-9011-da47560af...@elis.ugent.be
 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes


 On 06 Oct 2010, at 11:59, Michael Van Canneyt wrote:

 On Wed, 6 Oct 2010, Jonas Maebe wrote:

 Nobody else can steal the file once you have created it, because
 they won't be the owner nor have the necessary permissions. That is
 the main security risk and it is solved by this approach. The fact
 that another process running under your login not using O_EXCL
 could overwrite it is not an extra security risk (if you have a
 rogue process running under your login, nothing that you do is safe
 because it can use ptrace to modify any process in any way it sees
 fit anyway).

 And that is why I think the whole point is hugely exaggerated :-)

 It's not, because currently a process from *another* user can
 trivially intercept your temporary files. If you have a daemon running
 as root, that is a major security concern.


 Jonas


 --

 Message: 3
 Date: Wed, 6 Oct 2010 07:49:42 -0500
 From: Andrew Brunner andrew.t.brun...@gmail.com
 Subject: Re: [fpc-pascal] lNet getting the local IP
 To: FPC-Pascal users discussions fpc-pascal@lists.freepascal.org
 Message-ID:
        aanlktinkfgmjmfkls=tww+sorr3jmkj4zjul7z6zr...@mail.gmail.com
 Content-Type: text/plain; charset=ISO-8859-1

 I just read the first line in /etc/hosts file.  The first entry is the IPv4.

 On Tue, Oct 5, 2010 at 3:04 PM, Felipe Monteiro de Carvalho
 felipemonteiro.carva...@gmail.com wrote:
 hello,

 I am searching for a way to get the local IP. I already found examples
 with winsock, synapse and indy. Does anyone know how to do that with
 lNet?

 thanks,
 --
 Felipe Monteiro de Carvalho
 

[fpc-pascal] Destroy vs Free: Memory Leak?

2010-09-06 Thread Brian Winfrey
I have a TestCase that has this issue.  If I call obj.Free, I am
unable to step into the Destroy method and heaptrc indicates a memory
leak.  If I call obj.Destroy everything works as expected.  Following
the call to Free -
... if (obj  nil) then obj.Destroy;
it would seem that the object must be nil.  How can I test this?  i am
unable to step into objpas?.inc.

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