Page 1 of 1

Delphi XE2 (WIDEMEMO)

Posted: 23.12.2013, 16:00
by Edijus
Hello.
I have this SQL function in postgresql-9.3.2-1-windows-x64:

Code: Select all

CREATE OR REPLACE FUNCTION fnk_create_table(prm_name varchar, prm_surname varchar)
  RETURNS TABLE(clm_name varchar(3), clm_surname varchar(6)) AS
$BODY$
BEGIN
 RETURN QUERY select CAST(prm_name AS varchar(3)) as clm_name, CAST(prm_surname as varchar(6)) as clm_surname;
END;$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 1 SECURITY DEFINER ROWS 1;
ALTER FUNCTION fnk_create_table(varchar, varchar) OWNER TO postgres;
GRANT EXECUTE ON FUNCTION fnk_create_table(varchar, varchar) TO postgres;
When I run

Code: Select all

select * from fnk_create_table('Albert', 'Einstein ');
from pgAdmin Query window, I get:

Code: Select all

clm_name   clm_surname
Alb        Einste
Now, open Delphi XE2, create new VLC Forms Application. Place ZConnection1, ZQuery1, DataSource1 and DBEdit1 components on Form1.
Add this code in OnFormCreate event:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  ZConnection1.HostName := 'localhost';
  ZConnection1.User := 'postgres';
  ZConnection1.Password := 'your_password_here';
  ZConnection1.Database := 'postgres';
  ZConnection1.Protocol := 'postgresql-9';
  ZConnection1.Connected := True;
  ZQuery1.Connection := ZConnection1;
  ZQuery1.SQL.Add('select * from fnk_create_table(''Albert'', ''Einstein'');');
  ZQuery1.Open;
  DataSource1.DataSet := ZQuery1;
  DBEdit1.DataSource := DataSource1;
  DBEdit1.DataField := 'clm_name';
end;
When application runs, you will see (WIDEMEMO) in DBEdit1. You can try adding

Code: Select all

ZQuery1.FieldByName('clm_name').SetFieldType(TFieldType.ftString);
DBEdit1.Field.SetFieldType(TFieldType.ftString);
And yet result will be the same. What am I missing?
Windows 7 x64, ZEOSDBO-7.1.2-stable, Delphi XE2.

Re: Delphi XE2 (WIDEMEMO)

Posted: 24.12.2013, 04:26
by Edijus
Ahh, use char instead of varchar.