Solved

delphi override default streaming of published properties

Posted on 2013-06-03
8
593 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

937 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

3 Experts available now in Live!

Get 1:1 Help Now