Jump to content
Sign in to follow this  
Larry Hengen

AV Accessing EditValue in DevExpress Editors

Recommended Posts

I am using an ancient version (17.1.5) of the ExpressEditors and have a simple frame in which I am attempting to validate one editor based on the contents of two others.  From what I have found on-line and in the help it seems to me that accessing the EditValue of a TcxCustomEdit descendant should be fine at run-time, but I get an AV or other error in the debugger (Berlin) and the application does not behave correctly.  i have explored all other public properties as well, and none seem appropriate.  Anyone know the cause without tracing through all the DevExpress code?  In the TFrameDailyHours.editHoursPropertiesValidate method I am attempting to make sure the Hours edit does not contain a value that exceeds the difference of the two other time edit controls:

 

unit UnitFrameDailyHours;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxContainer, cxEdit, cxSpinEdit, cxTextEdit, cxMaskEdit, cxTimeEdit, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TFrameDailyHours = class(TFrame)
    PanelDay7: TPanel;
    labelDayofWeek: TStaticText;
    CheckBoxOvernight: TCheckBox;
    TimeEditStart: TcxTimeEdit;
    TimeEditStop: TcxTimeEdit;
    editHours: TcxSpinEdit;
    procedure TimeEditStartPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
      var Error: Boolean);
    procedure TimeEditStopPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
      var Error: Boolean);
    procedure editHoursPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
      var Error: Boolean);
  public
  end;

implementation

{$R *.dfm}

procedure TFrameDailyHours.TimeEditStartPropertiesValidate(Sender: TObject; var DisplayValue: Variant;
  var ErrorText: TCaption; var Error: Boolean);
begin
  ErrorText := '';

  //Start Date is a required field
  Error := VarIsNull(DisplayValue);
  if Error then
    ErrorText := 'Start of Time Range cannot be Empty';
  Exit;

  //if we have a StopTime then the StartTime must be < StopTime
  Error := (DisplayValue >= TimeEditStop.EditValue);
  if Error then
    ErrorText := 'Start of Time Range must precede End of Time Range';
end;

procedure TFrameDailyHours.TimeEditStopPropertiesValidate(Sender: TObject; var DisplayValue: Variant;
  var ErrorText: TCaption; var Error: Boolean);
begin
  ErrorText := '';
  if not (DisplayValue = EmptyStr) then
  begin
    Error := (DisplayValue < TimeEditStart.EditValue);
    if Error then
      ErrorText := 'End of Time Range must be Empty or after Start of Time Range';
  end;
end;

procedure TFrameDailyHours.editHoursPropertiesValidate(Sender: TObject; var DisplayValue: Variant;
  var ErrorText: TCaption; var Error: Boolean);
begin
  ErrorText := '';
  Error := False;

  if not (TimeEditStart.DisplayValue = '00:00:00') and not (TimeEditStop.DisplayValue = '00:00:00') then
  begin
    Error := VarIsNull(DisplayValue);
    if Error then
    begin
      ErrorText := 'Hours cannot be Empty';
      Exit;
    end;

    Error := (DisplayValue < 0) or (DisplayValue > 24);
    if Error then
    begin
      ErrorText := 'Hours must be > 0 and < 24';
      Exit;
    end;

    //check that Hours does not exceed duration between Start and Stop Times
    if TimeEditStop.EditValue > TimeEditStart.EditValue then
    begin
      Error := (TimeEditStop.EditValue - TimeEditStart.EditValue) * 24 < DisplayValue;
      if Error then
      begin
        ErrorText := 'Hours exceeds duration between Start and End Times';
        Exit;
      end;
    end;
  end;
end;

end.

Share this post


Link to post
Guest

You have EditValue, EditingValue, EditText and EditingText to "try".

Also there's a Time property.

Depending on settings like ImmediatePost and ValidationOptions those will reflect various things but i think you are aware.

DX support sometimes recommand what they call "Postponed execution" when accessing stuff from event handlers.

What they mean is to create a windows message handler and do a PostMessage to let execution "continue", i don't know if that will help here though.

 

Share this post


Link to post

Doesn't the debugger work for you?

Just place a breakpoint in the Validate event handler and examine (using Evaluate->Inspect) the properties of the controls in question. It should be easy to see which properties contains the values you need.

Share this post


Link to post

Thanks all for the responses.  Turns out the AVs are due to the debugger in Berlin exploding when attempting to inspect the variables and not my actual code.  Injected CodeSite Messages to find out the actual values at run-time and validate the code was correct.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×