Solved

Property editor needed {worth 200 pts!}

Posted on 2000-05-09
12
251 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 200 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 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