Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8242253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:06:15+00:00 2026-06-07T21:06:15+00:00

I developed a small application in Delphi with TEdit components on it. I used

  • 0

I developed a small application in Delphi with TEdit components on it.enter image description here
I used this function to validate if the component fields are not empty.

function TF_config.Validatefields:boolean;
var 
  i : integer;
begin
 for i := 0 to ComponentCount - 1 do
 begin
   if (Components[i]is TEdit) then
   begin
      if ((TEdit(Components[i]).Text) ='') then
      begin
        MessageDlg('Enter data in all the fields',mtWarning,[MBOK],0);
        TEdit(Components[i]).SetFocus;
        result := false;
        exit;
     end;             
   end;  //end for TEdit
 end;    //end component count 
 result := true;
end;

Now I have to add one more component
enter image description here
The order in which the function checks for data if valid is
ID->Name->Address->Phone->Age. But I want it to be ID->Name->Address->Age->Phone.
I tried solving it deleting the Phone Edit component and later add it after adding the Age Edit component.Or using the Phone Edit component for Age and add new Edit component for Phone. This is easier for few components, but becomes tedious when having many of them.
So I was wondering if we could arrange the components in a manner that suits us. Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:06:18+00:00Added an answer on June 7, 2026 at 9:06 pm

    I would suggest putting the controls in your own list/array, then you have full control over its content and ordering, and can loop through it when needed. This also ensures that you touch only the controls you are actually interested in and not wasting time touching other controls that you are not interested in, and it also allows the VCL to maintain its own ordering of its own internal lists as it sees fit.

    type
      TF_config = class(TForm)
        procedure FormCreate(Sender: TObject);
      ...
      private
        EditFields: array[0..4] of TEdit;
        function ValidateFields: Boolean; 
      ...
      end;
    
    procedure TF_config.FormCreate(Sender: TObject);
    begin
      EditFields[0] := IdEdit;
      EditFields[1] := NameEdit;
      EditFields[2] := AddressEdit;
      EditFields[3] := AgeEdit;
      EditFields[4] := PhoneEdit;
    end; 
    
    function TF_config.ValidateFields: Boolean; 
    var  
      i : integer; 
    begin 
      for i := Low(EditFields) to High(EditFields) do 
      begin 
        if EditFields[i].GetTextLen = 0 then 
        begin 
          MessageDlg('Enter data in all the fields', mtWarning, [MBOK], 0); 
          EditFields[i].SetFocus; 
          Result := False; 
          Exit; 
        end;              
      end;
      Result := True; 
    end; 
    

    Update: If you have multiple types of controls that you need to validate, you can do this instead:

    type 
      TF_config = class(TForm) 
        procedure FormCreate(Sender: TObject); 
      ... 
      private 
        Fields: array[0..4] of TControl; 
        function ValidateFields: Boolean;  
      ... 
      end; 
    
    procedure TF_config.FormCreate(Sender: TObject); 
    begin 
      Fields[0] := ...; 
      Fields[1] := ...; 
      ...
      Fields[4] := ...; 
    end;  
    
    function TF_config.ValidateFields: Boolean;  
    var   
      i : Integer;  
      ctrl: TControl;
    begin  
      Result := True;
      for i := Low(Fields) to High(Fields) do  
      begin  
        ctrl := Fields[i];
        if ctrl is TCustomEdit then // handles both TEdit and TMemo
        begin  
          if TCustomEdit(ctrl).GetTextLen = 0 then  
          begin  
            Result := False;
            Break;
          end;               
        end;
        if ctrl is TComboBox then
        begin  
          if TComboBox(ctrl).ItemIndex = -1 then  
          begin  
            Result := False;
            Break;
          end;               
        end;
        ... and so on ...
      end;
      if not Result then
      begin
        MessageDlg('Enter data in all the fields', mtWarning, [MBOK], 0);  
        ctrl.SetFocus;  
      end;
    end; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a small windows forms application in C#. This application simply manipulates
I was developed one small iphone business application...In my application i used the data
I have developed a small desktop application in c#(using windows forms). For this project
This is a really strange issue. I have developed a small MVC application and
I have a small GUI application developed with netbeans. I used the 'clean and
I developed small CakePHP application, and now I want to add one more table
I have developed a small application and now i want to protect it. I
i have developed a small application and was working fine on developing machine but
Hi i developed small web application, in that all the functionality working fine but
We have developed a small web application for a client. We decided on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.