Solved

delphi override default streaming of published properties

Posted on 2013-06-03
8
620 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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:Ephraim Wangoya
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 129
LAN or WAN ? 11 106
how to resize animated Gif image in delphi ? 1 45
update joined tables 2 62
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 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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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