Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Property editor needed {worth 200 pts!}

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
Eddie Shipman
Asked:
Eddie Shipman
  • 8
  • 4
1 Solution
 
mullet_attackCommented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
Well, Since I actually came up with my
own solution, I'll give you 100 points
for answering with a source solution.

0
Industry Leaders: 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!

 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
This question has a deletion request Pending
0
 
Eddie ShipmanAll-around developerAuthor Commented:
See above comment...
0
 
mullet_attackCommented:
This question no longer is pending deletion
0
 
mullet_attackCommented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
mullet_attackCommented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
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
 
Eddie ShipmanAll-around developerAuthor Commented:
Just to get rid of it all...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now