[Lazarus] TPQConnection and float
b.f.lundin at gmail.com
Mon Mar 21 22:48:09 CET 2016
I'm new to Lazarus (since Saturday)
but in the 90:ies id wrote some Turbo Pascal for school and liked it.
However, the last 15 years, I've worked with a system written in Ada
so that is the language I'm fluid in.
But it is close to Pascal.
So - I started to write a form with a tree widget and a graph,
and started go get data from a database to fill the graph with,
depending on the selected node in the tree.
But the values are off with a factor 10000.
I wrote a console test program to reproduce it,
and in also gets the floats wrong with a factor 10000.
Where should I report this - if this mailing list is not the place?
But perhaps first of all - am I doing something wrong here ?
Besides this, I am really impressed with Lazarus,
as an IDE.
I've already ordered some books at Amazon.
output as follows:
(Win7 , Postgres 9.4, libpq.dll also 9.4, Lazarus 1.6)
function CreateConnection: TPQConnection;
result := TPQConnection.Create(nil);
result.Hostname := 'some-server';
result.DatabaseName := 'some-db';
result.UserName := 'some-user';
result.Password := 'some-pass;
function CreateTransaction(pConnection: TPQConnection): TSQLTransaction;
result := TSQLTransaction.Create(pConnection);
result.Database := pConnection;
function CreateQuery(pTransaction: TSQLTransaction): TSQLQuery;
result := TSQLQuery.Create(pTransaction.Database);
result.Database := pTransaction.Database;
result.Transaction := pTransaction
PQConn : TPQConnection;
T : TSQLTransaction;
Q1, Q2, Q3 : TSQLQuery;
A : LongInt;
B,C : Double;
sSql : String;
PQConn := CreateConnection ;
T := CreateTransaction(PQConn);
Q1 := CreateQuery(T) ;
sSql := 'create table TEST ( ';
sSql += 'A integer not null primary key, ';
sSql += 'B numeric(8,3) not null , ';
sSql += 'C numeric(15,2) not null ) ';
Q1.SQL.Text := sSql;
Q2 := CreateQuery(T) ;
sSql := 'insert into TEST values (1, 1.0, 2.2)';
Q2.SQL.Text := sSql;
Q3 := CreateQuery(T) ;
sSql := 'select * from TEST order by A';
Q3.SQL.Text := sSql;
if not Q3.Eof then begin
A := Q3.FieldByName('A').AsLongint;
B := Q3.FieldByName('B').AsFloat;
C := Q3.FieldByName('C').AsFloat;
Writeln('A: ', A);
Writeln('B: ', B);
Writeln('C: ', C);
Writeln('round(B): ', round(B));
Writeln('round(C): ', round(C));
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus