Forum > Database

TStringsDataset, help needed

<< < (2/3) > >>

rvk:
I was just about to try using a TDataset-like descendant for accessing Google calendar and GMail after creating a OAuth2.0 library for the Google apis (for .Next/Prior etc) (see here).

What I did notice about your code is that you have GetFieldData and SetFieldData in the protected section of your descendant. I think you should have gotten an compiler warning saying that the visibility of those method is lower than in TDataSet (which is in public).

--- Code: ---Note: Virtual method "GetFieldData(TField;Pointer):Boolean;" has a lower visibility (protected) than parent class TDataSet (public)
Note: Virtual method "SetFieldData(TField;Pointer);" has a lower visibility (protected) than parent class TDataSet (public)

--- End code ---

That would mean that your GetFieldData and SetFieldData are never called. Move them to public and see if it works better.

taazz:

--- Quote from: rvk on July 08, 2015, 12:57:10 pm ---That would mean that your GetFieldData and SetFieldData are never called. Move them to public and see if it works better.

--- End quote ---
Erm no it doesn't. Lowering visibility is not supported as far as I know even if it was supported how do you think the protected virtual method work in the first place? The warning you see is a simple "FYI the visibility is not what you defined here" message and nothing else.

rvk:

--- Quote from: taazz on July 08, 2015, 01:45:34 pm ---
--- Quote from: rvk on July 08, 2015, 12:57:10 pm ---That would mean that your GetFieldData and SetFieldData are never called. Move them to public and see if it works better.

--- End quote ---
Erm no it doesn't. Lowering visibility is not supported as far as I know even if it was supported how do you think the protected virtual method work in the first place? The warning you see is a simple "FYI the visibility is not what you defined here" message and nothing else.

--- End quote ---
Woops... my bad ("lack of knowledge"  :-[)

I was under the impression the lower visibility would also mean the original public method of the base-class would still be called (and not the newer protected method). I was wrong.
 

--- Quote ---In practice this is never harmful, but it can be confusing to someone reading documentation and observing the visibility attributes of the document.
--- End quote ---
(Source)

jc99:

--- Quote from: rvk on July 08, 2015, 12:57:10 pm ---I was just about to try using a TDataset-like descendant for accessing Google calendar and GMail after creating a OAuth2.0 library for the Google apis (for .Next/Prior etc) (see here).

What I did notice about your code is that you have GetFieldData and SetFieldData in the protected section of your descendant. I think you should have gotten an compiler warning saying that the visibility of those method is lower than in TDataSet (which is in public).

--- Code: ---Note: Virtual method "GetFieldData(TField;Pointer):Boolean;" has a lower visibility (protected) than parent class TDataSet (public)
Note: Virtual method "SetFieldData(TField;Pointer);" has a lower visibility (protected) than parent class TDataSet (public)

--- End code ---

That would mean that your GetFieldData and SetFieldData are never called. Move them to public and see if it works better.

--- End quote ---
I used TMemDataset as a Template,
And in memds.pas (line 85 ,91 & 109 ) you see that they also lower the visibility of these Methods.
however in  TCustomBufDataset (BufDataset Line 512, 516 ff ) these methods are public.

rvk:
Do you also have some small test-program.

I tried your source with the following and it worked.

--- Code: ---a=test
b=ok

--- End code ---
became

--- Code: ---a=test
b=ccccc

--- End code ---


--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
begin
    ds.Edit;
    ds.FieldByName('b').asString := 'ccccc';
    ds.Post;
    Showmessage(ds.Source.Text);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  sl: TStringList;
begin
  sl := TStringList.Create;
  sl.Add('a=test');
  sl.Add('b=ok');
  ds := TStringsDataSet.Create(Self);
  ds.Source := sl;
  ds.Open;
  DataSource1.DataSet := ds;
end;

--- End code ---

What exactly is going wrong at your end?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version