?
Solved

Property editor needed {worth 200 pts!}

Posted on 2000-05-09
12
Medium Priority
?
256 Views
Last Modified: 2013-11-23
I have a component that takes a TDataset
and formats its result to XML. I need a
property and property editor that will
allow the selection of which fields in
the dataset to use as Attributes. The
other fields not selected will be
presented as Elements in the resulting
XML document.

I'm thinking of having a dialog with a
TCheckListBox on it where the
AttributeFields can be checked.

This is the next-to-last thing I need
for this component and I don't know
where to begin on this one...

If you have specific questions, contact
me via e-mail at eshipman@e-mds.com...

0
Comment
Question by:EddieShipman
[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
  • 4
12 Comments
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2795282
Here is an example of a simple component that has a non-standard property "Stuff", of type TStuff, a record.

Double-clicking TMyComponent invokes a component editor where you can edit the fields of Stuff.

Right-clicking has a context menu where some simple actions can occur.

Because TStuff is a non-standard property type, I've added TFiler code to stream the fields of TSTuff to/from the *.DFM

I'll post the code here in case other E-E people want to read it, and I'll e-mail the sample app to you.

----------------------------
TMyComponent
----------------------------
unit Mycomponent;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DsgnIntf,
  StuffEditor;

type
  TStuff = record
    Number : integer;
    Text : string[255];
  end;

  TMycomponent = class(tcomponent)
  private
    fStuff :TStuff;
    procedure SetStuff(const Value: TStuff);
    procedure DefineProperties(Filer:TFiler);override;
    procedure WriteStuffText(Writer:TWriter);
    procedure ReadStuffText(Reader:TReader);
    procedure WriteStuffNumber(Writer:TWriter);
    procedure ReadStuffNumber(Reader:TReader);
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    property Stuff : TStuff read FStuff write SetStuff;
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Planetech', [TMycomponent]);
  RegisterComponentEditor(TMycomponent,TStuffEditor);
end;

{ TMycomponent }

procedure TMycomponent.DefineProperties(Filer: TFiler);
begin
  inherited;
  Filer.DefineProperty('Text', ReadStuffText, WriteStuffText, fStuff.text <> '');
  Filer.DefineProperty('Number', ReadStuffNumber, WriteStuffNumber, fStuff.number <> 0);
end;

procedure TMycomponent.ReadStuffNumber(Reader: TReader);
begin
  fStuff.Number := Reader.ReadInteger;
end;

procedure TMycomponent.ReadStuffText(Reader: TReader);
begin
  fStuff.Text := Reader.ReadString;
end;

procedure TMycomponent.SetStuff(const Value: TStuff);
begin
  FStuff := Value;
end;

procedure TMycomponent.WriteStuffNumber(Writer: TWriter);
begin
  Writer.WriteInteger(fStuff.Number);
end;

procedure TMycomponent.WriteStuffText(Writer: TWriter);
begin
  Writer.WriteString(fStuff.Text);
end;

end.

--------------------
TStuffEditor
--------------------
unit StuffEditor;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Spin, dsgnIntf;

type
  TStuffEditor = class(TComponentEditor)
  function GetVerbCount:integer;override;
  function GetVerb(index:integer):string;override;
  procedure ExecuteVerb(index:integer);override;
 end;

  TStuffDLG = class(TForm)
    Edit1: TEdit;
    SpinEdit1: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
  private
    { Private declarations }
  public
    function Execute(Component : TComponent) : boolean;
  end;

var
  StuffDLG: TStuffDLG;

implementation

uses MyComponent;

{$R *.DFM}

{ TStufEditor }

procedure TStuffEditor.ExecuteVerb(index: integer);
var
  tmpStuff : TStuff;
begin
  inherited;
  case index of
    0 :
      begin
        try
          StuffDlg := TStuffDlg.create(nil);
          if StuffDlg.execute(Component) then Designer.Modified;
        finally
          StuffDlg.free;
        end;
      end;
    1 :
      begin
        tmpStuff := TMyComponent(Component).Stuff;
        tmpStuff.Text := 'hello world';
        TMyComponent(Component).Stuff := tmpStuff;
        Designer.Modified;
      end;
    2 :
      begin
        tmpStuff := TMyComponent(Component).Stuff;
        tmpStuff.Text := 'foo';
        TMyComponent(Component).Stuff := tmpStuff;
        Designer.Modified;
      end;
  end;

end;

function TStuffEditor.GetVerb(index: integer): string;
begin
  case index of
    0:result := 'Open Dialog';
    1:result := 'StuffText := hello world';
    2:result := 'StuffText := foo';
  end;
end;

function TStuffEditor.GetVerbCount: integer;
begin
  result := 3;
end;

{ TStuffDLG }

function TStuffDLG.Execute(Component: TComponent): boolean;
var
  tmpStuff : TStuff;
begin
  tmpStuff := TMyComponent(Component).Stuff;
  edit1.text := tmpStuff.Text;
  spinedit1.value := tmpStuff.Number;
  ShowModal;
  result := ModalResult = mrOK;
  if result then
    begin
      tmpStuff.text := edit1.text;
      tmpStuff.number := spinedit1.value;
      TMyComponent(Component).Stuff := tmpStuff;
    end;
end;

end.

----------------
StuffEditor DFM
----------------
object StuffDLG: TStuffDLG
  Left = 335
  Top = 212
  Width = 321
  Height = 198
  Caption = 'Stuff Editor'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 24
    Width = 37
    Height = 13
    Caption = 'Number'
  end
  object Label2: TLabel
    Left = 24
    Top = 88
    Width = 21
    Height = 13
    Caption = 'Text'
  end
  object Edit1: TEdit
    Left = 120
    Top = 80
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
  end
  object SpinEdit1: TSpinEdit
    Left = 120
    Top = 24
    Width = 121
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 1
    Value = 0
  end
  object Button1: TButton
    Left = 232
    Top = 136
    Width = 75
    Height = 25
    Caption = 'OK'
    ModalResult = 1
    TabOrder = 2
  end
end
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2796259
I need something more along the lines of the TFieldsEditor where I can build
a fieldlist of fields I want to write
as Attributes.

This is for strings only...
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2797107
Well, Since I actually came up with my
own solution, I'll give you 100 points
for answering with a source solution.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Author Comment

by:EddieShipman
ID: 2797119
I can't lower thepoints offered so I am deleting the question. If you'll
resubmit your answer, I'll accept it
for 100 points since you offered a
source soultion. I did, however, use
my own solution.

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2797120
This question has a deletion request Pending
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2797125
See above comment...
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2798079
This question no longer is pending deletion
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2798080
Eddie, You said you didn't know where to start on this one. I gave you a complete working example of a component editor 7 hours after you asked the question, and one day later you worked it out yourself.

If you didn't use my answer at all, then delete the question with no points given, otherwise accept this answer.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2800271
Cosidering, you posted a component editor .vs a property editor and I
needed a TStrings editor .vs an editor
for a Record, what do you think. I wrote
a TStrings PROPERTY editor and didn't
use any of your code at all. I'm
sending you a copy of the code to your
e-mail address to confirm it...

If you still want the 200 after seeing
my code, I'll approve it.

E
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 800 total points
ID: 2800574
Eddie,

I don't care to argue the point. I have withdrawn my answer and you can delete the question.

I would like to comment on your question tho'...

You wanted an editor to edit the fields in a dataset. Ok, I took a punt on a component editor because that's what a dataset uses, not a property editor (property editors work with published properties)

You wanted to store the field names with some *unknown* (to me) attributes, including checked or not. Again I took a punt and thought you might like to store this data in a TList of records.

You did not say you wanted a TStrings editor.

Later, you wanted something "along the lines of the TFieldsEditor".

I can only try to answer a question based on the information in that question.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2800587
Well even your editor wasn't what I was looking for. If it had been a fields editor, sure, I would have probably used it. I couldn't see any way to conform it to what I was needing...

Sorry but I guess I didn't make myself clear enough...
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 2801138
Just to get rid of it all...
0

Featured Post

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!

Question has a verified solution.

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

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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, left to enroll

801 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