#1 2011-02-17 23:21:29

migajek
Member
Registered: 2010-10-01
Posts: 89

Main Field Name problem

Hi,
I'm playing with the UIEdit, and I tried editing the record which has related fields ...
first of all I was quite amazed that the related fields were of combobox type wink

But all the combos were empty. Debugging and investigating I found out that fMainFieldName contains empty string for each model.
Following that path I changed SQLIte3Commons:9068 from "sftUTF8Text: begin" to "sftUTF8Text, sftAnsiText: begin"
(I haveall the fields declared as UTF8String, BTW ... but the type was always sftAnsiText).

so it now fills "non-unique" array of names ... but still the "unique" part is empty .. what am I doing wrong?

Offline

#2 2011-02-18 10:46:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Main Field Name problem

It's because you used sftAnsiText for your main field, whereas the framework expect it to be sftUTF8Text.

sftAnsiText will be converted as UTF-8 when stored in the DB, so perhaps it's not worth it here...

Offline

#3 2011-02-18 13:11:38

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Main Field Name problem

ok, so I've reverted all the changes back to your version. Than declaret two records:

    TSQLCourse = class(TSQLRecord)
    private
    //fields declaration here
    published
        property Instructor: TSQLPerson read fInstructor write fInstructor;
        property Person: TSQLPerson read wPerson write fPerson;

and

    TSQLPerson = class(TSQLRecord)
    private
        fName: RawUTF8;
        fSurname: RawUTF8;
        fPhone: RawUTF8;
    published
        property Name: RawUTF8 read fName write fName;
        property Surname: RawUTF8 read fSurname write fSurname;
        property Phone: RawUTF8 read fPhone write fPhone;
    end;


I have some "person" records.
Now when I call TRecordEditForm on TSQLCourse, both comboboxes are empty ...

//debugging the model creation, I found out that in my case the P^.StoredProc never equals to integer(false), so the "Unique" flag is never being set to true ... thus fMainFieldName[false,x] is never filled with data.

// it seems that P^.StoredProc always equals to decimal number 1. At least for all the records I debugged it, including MainDemo records.

Last edited by migajek (2011-02-18 14:04:34)

Offline

#4 2011-02-18 16:52:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Main Field Name problem

You should set

property Name: RawUTF8 read fName write fName; stored false;

to make this field unique...

But it's not a good idea since two persons may have the same name!

I'll go and see what can be modified.

Offline

#5 2011-02-18 17:21:49

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Main Field Name problem

ab wrote:

stored false;

there's so much I have to learn about RTTI yikes

yeah, indeed making that field unique is not the best idea ... but current way of handling automated relation edition makes it practically useless sad

Offline

#6 2011-02-19 08:19:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Main Field Name problem

We'll need to have some other custom display of record if there is no unique field: like Name+' '+FirstName or such...

Offline

#7 2011-02-19 11:11:50

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Main Field Name problem

ab wrote:

We'll need to have some other custom display of record if there is no unique field: like Name+' '+FirstName or such...

Yes, that's what I did as for now - I did following:

    function GetFullName: RawUTF8;
published
    property FullName: RawUTF8 read GetFullName stored false;

/// ....

function TSQLPerson.GetFullName: RawUTF8;
begin
  result:= fSurname + ', ' + fName;
end;

which actually works, but is tricky - creates completely unnecessary field in SQL, also displays the field in UIEditor.

If I don't define my own unique field, ID is default one, right?
So, how about using ID as unique field for internal operations (storing it in ComboBox.Items.Objects casted to TObject) while for displaying create virtual method in TSQLRecord, called GetUniqueDisplayName - which could be implemented by user, or - if it's not implemented - just use first sftUTF8Text field?

Offline

#8 2011-02-19 13:20:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Main Field Name problem

If you put a _ before the property name, like _FullName, it won't appear in the UIEditor.

Offline

#9 2011-02-19 13:25:37

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Main Field Name problem

ab wrote:

If you put a _ before the property name, like _FullName, it won't appear in the UIEditor.

Thanks, but

1. appears in the Grid (TSQLTableToGrid)
2. uses additional memory in the database (which is not that important, but still...)
3. I guess it's slower than ID-based record identification

but for a quick fix it's pretty good wink

Last edited by migajek (2011-02-19 13:25:53)

Offline

#10 2011-02-20 09:24:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Main Field Name problem

The UIEditor is best used with the global User Interface description of the framework.

You're trying to reinvent the wheel...

Take a look at the TSQLRibbon and TSQLRibbonTabParameters classes, as used for instance in our main demo.

By just filling TSQLRibbonTabParameters following fields, the UIEditor window know how to show or handle the data:

    /// the associated hints to be displayed during the edition of this table
    // - every field hint must be separated by a '|' character
    // (e.g. 'The First Name|Its Company Name')
    // - all fields need to be listed in this text resource, even if it won't
    // be displayed on screen (enter a void item like ||)
    // - you can define some value by setting a pointer to a resourcestring
    EditFieldHints: PResStringRec;
    /// write hints above field during the edition of this table
    // - if EditExpandFieldHints is TRUE, the hints are written as text on the
    // dialog, just above the field content; by default, hints are displayed as
    // standard delayed popup when the mouse hover the field editor
    EditExpandFieldHints: boolean;
    /// the associated field name width (in pixels) to be used for creating
    // the edition dialog for this table
    EditFieldNameWidth: integer;
    /// a CSV list of field names to be hidden in both editor and default report
    // - handy to hide fields containing JSON data or the name of another
    // sftRecord/sftID (i.e. TRecordReference/TSQLRecord published propet) fields
    // - list is to be separated by commas (e.g. "RunLogJSON,OrdersJSON" or
    // "ConnectionName")
    EditFieldNameToHideCSV: RawUTF8;
    /// if the default report must contain the edit field hints
    // - i.e. if the resourcestring pointed by EditFieldHints must be used
    // to display some text above every property value on the reports 
    EditFieldHintsToReport: boolean;

There is room to improvement, of course.
- Record selection via a TComboBox works only if the record has an unique main textual property.
- Validation needs to be extended in a n-Tier way - see your own article in http://synopse.info/forum/viewtopic.php?id=231 - I'm working on it.

Offline

#11 2011-02-22 21:29:26

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Main Field Name problem

ab wrote:

You're trying to reinvent the wheel...

indeed. that's because I needed to implement very simple TSQLRibbon equivalent, but TMS-independent.
Removing TMS dependencies from UIEdit form was fast and easy, so I decided to create very simple general editor with grid preview on my own ... anyway, thanks for the tips!

Offline

Board footer

Powered by FluxBB