Solved

delphi override default streaming of published properties

Posted on 2013-06-03
8
582 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now