I am having issues debugging the following code, I really need help as we have an exam tomorrow! Whenever I try to change the combo box the program stops responding. Please let me know if you spot the issue, I'm sure it's glaringly obvious...
Thanks in advance Chris
Edit: I'm really new here, I'm sorry that I wasn't more specific. I have added all of the code. The only reason that I didn't initially do that is because I thought that the issue was most likely with the TForm1.ComboBox1Change procedure, because the .exe crashes (windows says that it is not responding, I have attached an image) whenever I change the combobox. I am sorry if I wasted anyone's time. I was also incorrect when I said that I was having issues debugging it. What I mean is that I am struggling to find the issue that is causing this. I have also attached the task brief.
unit VehicleManager_u;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Car, Vcl.StdCtrls, Vcl.Samples.Spin;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Edit1: TEdit;
SpinEdit1: TSpinEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
Car1 : TCar;
Car2 : TCar;
Car3 : TCar;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Car1 := TCar.Create('', 0, 0.0);
Car2 := TCar.Create('', 0, 0.0);
Car3 := TCar.Create('', 0, 0.0);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
If ComboBox1.Text = 'Car 1' then
begin
Edit1.Text := Car1.GetMake;
SpinEdit1.Value := Car1.GetYearMade;
Edit2.Text := FloatToStr(Car1.GetValue);
end
Else if ComboBox1.Text = 'Car 2' then
begin
SpinEdit1.Value := Car2.GetYearMade;
Edit2.Text := FloatToStr(Car2.GetValue);
end
Else if ComboBox1.Text = 'Car 3' then
begin
Edit1.Text := Car3.GetMake;
SpinEdit1.Value := Car3.GetYearMade;
Edit2.Text := FloatToStr(Car3.GetValue);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If ComboBox1.Text = 'Car 1' then
begin
Car1.SetMake(Edit1.Text);
Car1.SetYearMade(SpinEdit1.Value);
Car1.SetValue(StrToFloat(Edit2.Text));
end
Else if ComboBox1.Text = 'Car 2' then
begin
Car2.SetMake(Edit1.Text);
Car2.SetYearMade(SpinEdit1.Value);
Car2.SetValue(StrToFloat(Edit2.Text));
end
Else if ComboBox1.Text = 'Car 3' then
begin
Car3.SetMake(Edit1.Text);
Car3.SetYearMade(SpinEdit1.Value);
Car3.SetValue(StrToFloat(Edit2.Text));
end;
end;
end.
Here is the code from the object:
unit Car;
interface
type
TCar = class(TObject)
private
Make : String;
YearMade : Integer;
Value : Double;
public
constructor Create(MakeIn : String; YearMadeIn : Integer; ValueIn : Double);
procedure SetMake(MakeIn : String);
function GetMake: String;
procedure SetYearMade(YearMadeIn : Integer);
function GetYearMade : Integer;
procedure SetValue(ValueIn : Double);
function GetValue : Double;
function ToString : String;
end;
implementation
uses
SysUtils;
constructor TCar.Create(MakeIn : String; YearMadeIn : Integer; ValueIn : Double);
begin
Make := MakeIn;
YearMade := YearMadeIn;
Value := ValueIn;
end;
procedure TCar.SetMake(MakeIn: string);
begin
Make := MakeIn;
end;
function TCar.GetMake;
begin
Result := GetMake;
end;
procedure TCar.SetYearMade(YearMadeIn: Integer);
begin
YearMade := YearMadeIn;
end;
function TCar.GetYearMade;
begin
Result := GetYearMade;
end;
procedure TCar.SetValue(ValueIn: Double);
begin
Value := ValueIn;
end;
function TCar.GetValue;
begin
Result := GetValue;
end;
function TCar.ToString;
begin
Result := 'Make: ' + Make + ', Year Made: ' + IntToStr(YearMade) + ', Vale: R' + FloatToStr(Value);
end;
end.