Re: [fpc-pascal] TPersistent overhead

2016-03-27 Thread Michael Van Canneyt



On Sun, 27 Mar 2016, Ryan Joseph wrote:


Great, thanks Michael.

I had another idea. Is it really required to subclass TPersistent for RTTI 
information or can I just use {$M+} on the units that I need and leave the 
class hierarchy the same?


Using

{$M+}

For classes that need RTTI is sufficient. I do this myself.

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


Re: [fpc-pascal] TPersistent overhead

2016-03-27 Thread Ryan Joseph
Good idea thanks.

> On Mar 27, 2016, at 5:00 PM, fpc-pascal-requ...@lists.freepascal.org wrote:
> 
> Depending on your needs, you don't need to descend from TPersistent just
> to get RTTI information in your classes. Simply wrap a TObject
> descendant with {$M+} and deactivate the RTTI after the class definition.
> 
> For example:
> 
>  {$M+}
>  TtiVisited = class(TObject)
>... define your class interface here...
>  end;
>  {$M-}

Regards,
Ryan Joseph

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


[fpc-pascal] Postgresql interface bronken for Raspberry pi model 1b

2016-03-27 Thread Björn Lundin
Hi!
I'm using a pi as a monitor for some process, so I'm trying to get SDL2
and a working postgres interface on it.

However I'm running into trouble on timestamps fields on the pi.

I wrote a console program on Win7, using 32-bit compiler bundled with
Lazarus 1.6. (I think is is fpc 3.0.0)
and that platform can connect to the db, and run the program.



C:\pascal\pg_test_float>test_float.exe
A: 1
B:  1.E+000
C:  4.2457016203831023E+004
round(B): 1
round(C): 42457



The same program on the pi crashes.

pi@raspberrypi ~ $ fpc -v
Free Pascal Compiler version 2.6.0-9+rpi1+wsf1 [2015/04/28] for arm
Copyright (c) 1993-2011 by Florian Klaempfl and others

pi@raspberrypi ~ $ uname -a
Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015
armv6l GNU/Linux


pi@raspberrypi ~/svn/bnlbot/botstart/bot-1-0/source/pascal $ ./test_float
An unhandled exception occurred at $000302D4 :
EDatabaseError :  : Unknown fieldtype for parameter "DT".
  $000302D4
  $0001C4D0
  $00020DE8
  $8760

pi@raspberrypi ~/svn/bnlbot/botstart/bot-1-0/source/pascal $ addr2line
-e test_float 000302D4 0001C4D0 00020DE8 8760
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:85
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:85
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:85
/home/pi/svn/bnlbot/botstart/bot-1-0/source/pascal/test_float.lpr:57


where line 57 is market < here in code below
ie. Q2.Params.ParamByName('DT').Value := now;


program test_float;
uses
pqconnection,sqldb,sysutils,db;

function CreateConnection: TPQConnection;
begin
  result := TPQConnection.Create(nil);
  result.Hostname := 'db.somewhwew.com';
  result.DatabaseName := 'asd';
  result.UserName := 'asd';
  result.Password := 'pwd';
end;

function CreateTransaction(pConnection: TPQConnection): TSQLTransaction;
begin
  result := TSQLTransaction.Create(pConnection);
  result.Database := pConnection;
end;

function CreateQuery(pTransaction: TSQLTransaction): TSQLQuery;
begin
  result := TSQLQuery.Create(pTransaction.Database);
  result.Database := pTransaction.Database;
  result.Transaction := pTransaction
end;

var
PQConn : TPQConnection;
T  : TSQLTransaction;
Q1, Q2, Q3 : TSQLQuery;

A : LongInt;
B : Double;
C : TDateTime;

sSql : String;
begin
  PQConn := CreateConnection ;
  PQConn.Open;
  T := CreateTransaction(PQConn);
  T.StartTransaction;

  Q1 := CreateQuery(T) ;
  sSql := 'create table TEST ( ';
  sSql += 'A integer not null primary key, ';
  sSql += 'B numeric(8,3) not null , ';
  sSql += 'C timestamp(3) without time zone not null ) ';

  Q1.SQL.Text := sSql;
  Q1.ExecSql;

  Q2 := CreateQuery(T) ;
  sSql := 'insert into TEST values (1, 1.0, :DT)';
  Q2.SQL.Text := sSql;
  Q2.Prepare;
  //Q2.Params.ParamByName('DT').DataType := ftDateTime;
  Q2.Params.ParamByName('DT').Value := now;