Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delphi override default streaming of published properties

Posted on 2013-06-03
8
Medium Priority
?
657 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

597 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