Solved

delphi override default streaming of published properties

Posted on 2013-06-03
8
604 Views
Last Modified: 2013-06-13
Hi,

we have TPersistent class of published property which we don't want to stream at designtime but to stream in runtime. First idea is to somehow override streaming and to detect csDesigning:
When it is csDesigning then not to stream but not csDesigning -> stream.

thank you,
vojko cendak
0
Comment
Question by:vojkocendak
8 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 39219025
Yes, I also suggest using csdesigning to solve your problem:

Use it as follows...
if csDesigning in ComponentState then
    ShowMessage('Design-time')
  else
    ShowMessage('Runtime');

Open in new window

0
 

Author Comment

by:vojkocendak
ID: 39219779
The property is already published and part of then dfm streaming mechanism.
I want to override the streaming of the property. I found a solution
to include function stored

TCustomTag=class(TComponent)
published
  mypropname:string read fprop write fprop stored getIsStored:
end;

// designing -> doesn't store, in runtime it stores
function TCustomTag.getIsStored: Boolean;
begin
  result := not  (csDesigning in ComponentState)
end;

Open in new window


I thought I could just override the streaming with:
  Filer.DefineProperty(' mypropname',myReadProperty,myWriteProperty,true);

Open in new window

but if I do that it actually streams two properties with name ' mypropname' not my
defined property. I'm not sure.

thank you
0
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 39224510
Stored directive decides whether the value is stored in the dfm...You can view the form as text...Alt f12 or right click on the form and click on View As Text.  You can see the values of the published properties

Your
Filer.DefineProperty(' mypropname',myReadProperty,myWriteProperty,true); 

Open in new window

should  be in override of procedure TCustomTag.DefineProperties(Filer: TFiler); override;

Check out this article by Steve and Xavier on how to handle streaming of component data...

http://www.informit.com/articles/article.aspx?p=28278
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:vojkocendak
ID: 39224792
I though that also, but here's test component, where I want to override Value property.
I get TWO Values in component string stream !?
(Delphi2009ent)

tmyobject=class(TComponent)
  private
    fValue: variant;
    fq: word;
    procedure Readproperty(Reader: TReader);
    procedure Writeproperty(Writer: TWriter);
    function asStoreVariant: Boolean;
  protected
    procedure DefineProperties(Filer: TFiler); override;
  public
  published
    property Value:variant read FValue write FValue stored asStoreVariant;
    property Quality:word read fq write fq;
end;

implementation

function ComponentToStringProc(Component: TComponent): string;
var
  BinStream:TMemoryStream;
  StrStream: TStringStream;
  s: string;
begin
  BinStream := TMemoryStream.Create;
  try
    StrStream := TStringStream.Create(s);
    try
      BinStream.WriteComponent(Component);
      BinStream.Seek(0, soFromBeginning);
      ObjectBinaryToText(BinStream, StrStream);
      StrStream.Seek(0, soFromBeginning);
      Result:= StrStream.DataString;
    finally
      StrStream.Free;
    end;
  finally
    BinStream.Free
  end;
end;



procedure tmyobject.Readproperty(Reader: TReader);
begin
  FValue := Reader.ReadString;
end;

procedure tmyobject.Writeproperty(Writer: TWriter);
begin
    writer.WriteString('should override published value'); // ?
end;


function tmyobject.asStoreVariant: Boolean;
begin
  result := not (csDesigning in ComponentState); // <== this one works
end;

procedure tmyobject.DefineProperties(Filer: TFiler);
begin
  Filer.DefineProperty('Value', Readproperty, Writeproperty, true);
end;

procedure TForm1.btnButton1Click(Sender:TObject);
var
  lobj: tmyobject;
  S: string;
begin
  lobj := tmyobject.Create(nil);
  try
    lobj.FValue := 123455;
    lobj.Quality := 192;
    XML := ComponentToStringProc(lobj);
    Memo1.Text := Memo1.Text+XML;
  finally
     lobj .free
  end;
end;

Open in new window


thank you
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 500 total points
ID: 39226889
You don't need it in both published and in the DefineProperties...move Value to public...and it should work...

-Rick
0
 

Author Comment

by:vojkocendak
ID: 39227272
I want to explain myself more thoroughly, what we need:

When we work in designtime, we don't want  to store Value. But we need value in runtime streaming, because it's being transferred automatically by other CS framework, which streams all published properties (Value included), without additional programming.  So we can use same model of component.

This is so far we can explain.

Thank You

-Vojko
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 39232137
Remove the property from Published section, just make it public

Then on ReadProperty and WriteProperty, check for csDesigning
0
 

Author Comment

by:vojkocendak
ID: 39245912
OK, although it was not the way we intended we accept this as partly solution.
The solution was "stored getIsStored", beacuse we don't want to have public -> published property, only published, because we need it in other CS framework and NOT designtime.

thank you
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question