Solved

Simulation of Variant type property

Posted on 1997-08-23
4
217 Views
Last Modified: 2013-11-23
Do you know how to simulate a VARIANT Type on published property ?
0
Comment
Question by:dsam
[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
  • 3
4 Comments
 
LVL 1

Expert Comment

by:sassas081597
ID: 1342302
via Pointer
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 200 total points
ID: 1342303
Yes i know how.

but full implementation is for you.
This is template only and with new button which have variant property. You must decide which variants you need (integer, string, float ...).
You must write own GetValue and SetValue to do conversion from and to string which will shown in Object Inspector.

unit Varcomp;

interface

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

type
  TTestVariant = class(TButton)
  private
    fVariant : Variant;
  protected {}
  public {}
  published {}
    property TestPropVariant : variant read fVariant write fVariant;
  end;

procedure Register;

implementation

uses
  DsgnIntf;

type
  TVarRecProperty = class(TPropertyEditor)
  public
    function AllEqual: Boolean; override;
    function GetValue: string; override;
    procedure SetValue(const Value: string); override;
  end;

procedure Register;
begin
  RegisterComponents('Samples', [TTestVariant]);
  RegisterPropertyEditor( TypeInfo(Variant), TComponent, '', TVarRecProperty );
end;

function TVarRecProperty.AllEqual: Boolean;
var
  I: Integer;
  V: Variant;
begin
  Result := False;
  if PropCount > 1 then
  begin
    V := GetVarValue;
    for I := 1 to PropCount - 1 do
      if GetVarValueAt(I) <> V then Exit;
  end;
  Result := True;
end;

function TVarRecProperty.GetValue: string;
var Vv : Variant;
begin
  Vv := GetVarValue;
  Result := '12.12';  { here you must change Variant Vv to string }
end;

procedure TVarRecProperty.SetValue(const Value: string);
var V : Variant;
begin
  Vv := 12.12; { here you must change String to Vv Variant Value }
  SetVarValue( Vv );
end;

end.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342304
Hi
What happened ? Any questions ?
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1342305
another man on holliday.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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