Witam, główkowałem dosyć długo, ale w końcu nie wymyśliłem, co może być rozwiązaniem mojego problemu, stąd piszę tu.
Problem jest taki, że wywala mi błąd w trakcie pracy programu, kiedy chcę przypisać do elementu tablicy a[y+1] jakąś wartość. Nie ma tego problemu przy pojedynczej zmiennej.
procedure TForm1.Button1Click(Sender: TObject);
var
a: array [1..20] of INTEGER;
b,c, x, q, g: INTEGER;
r: string;
y: INTEGER;
begin
b:=StrToInt(Edit1.Caption);
x:=StrToInt(Edit2.Caption);
c:=StrToInt(Edit3.Caption);
if RadioButton1.Checked and RadioButton7.Checked then begin
y:=1;
REPEAT
(!) a[y+1]:=b+x+c;
Inc(y);
UNTIL (y+1=q);
end;
r:=IntToStr(g);
Label2.Caption:=r;
end;
Problem tkwi w linjce (!) a[y+1]. Wywala błąd external SVGHJ czy coś takiego przy tym wierszu.
@[alex] , jak zwykle pomagasz mi w takiej sytuacji, za co serdeczne dziękuję. Totalny fail, z tą pętlą. Tablica ma ograniczoną wartość, ponieważ szukałem błędu…
Ok, ten problem zażegnany, ale co u licha jest nie tak z kodem
var
a: array of INTEGER;
b,c, x, q, g: INTEGER;
r: string;
y: INTEGER;
begin
a[y]:=StrToInt(Edit5.Caption);
q:=StrToInt(Edit6.Caption);
b:=StrToInt(Edit1.Caption);
x:=StrToInt(Edit2.Caption);
c:=StrToInt(Edit3.Caption);
if RadioButton1.Checked and RadioButton7.Checked then begin
for y:=1 to q do begin a[y+1]:=b+x+c; end;
end;
r:=IntToStr(g);
Label2.Caption:=r;
end;
Tablica a jest typu integer, chce zamienić text na integer, spoko, czyli StrToInt powinno śmigać, ale niestety znowu wywala mi przy a[y]:=StrToInt(Edit5.Caption) błąd, ten external bla bla. Proszę o pomoc.
Program działa, dzięki jeszcze raz [alex], jeszcze tylko jedna sprawa: czy da się ustawić jakoś Caption dla Edit? Bo w Lazarusie nie mogę tego znaleźć w menu Właściwości… Chodzi mi o to, żeby zamiast napisu “Edit1” pojawiało się puste pole… Pozycja Name na niewiele się sprawdza. Szukałem w google - bez skutku.
– Dodane 13.11.2012 (Wt) 19:42 –
Ok, znalazłem w pozycji “ulubione” przy “Tekst”, prawidłowo?
– Dodane 13.11.2012 (Wt) 19:48 –
Dobra, sprawa nadal aktualna, wszystko śmiga talala i błędzioch tutaj:
GetTextMethod := TMethod(@Self.GetTextBuf);
(plik control.inc)
Chyba się jeszcze długo namęczę…
Kod dla całego Buttona:
procedure TForm1.Button1Click(Sender: TObject);
var
a: array of Extended;
b,c: Extended;
r: string;
y,q: integer;
z:integer;
begin
Liczba1.Caption:=' ';
Liczba2.Caption:=' ';
Edit5.Caption:=' ';
Edit6.Caption:=' ';
y:=1;
a[y]:=StrToFloat(Edit5.Caption);
q:=StrToInt(Edit6.Caption);
b:=StrToFloat(Liczba1.Caption);
c:=StrToFloat(Liczba2.Caption);
SetLength(a,100);
if RadioButton1.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b+a[y]+c;
if RadioButton1.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b+a[y]+c;
if RadioButton1.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b+a[y]*c;
if RadioButton1.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b+a[y]/c;
if RadioButton2.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b-a[y]+c;
if RadioButton2.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b-a[y]-c;
if RadioButton2.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b-a[y]*c;
if RadioButton2.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b-a[y]/c;
if RadioButton3.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b*a[y]+c;
if RadioButton3.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b*a[y]-c;
if RadioButton3.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b*a[y]*c;
if RadioButton3.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b*a[y]/c;
if RadioButton4.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b/a[y]+c;
if RadioButton4.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b/a[y]-c;
if RadioButton4.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b/a[y]*c;
if RadioButton4.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b/a[y]/c;
if NOT RadioButton1.Checked and NOT RadioButton2.Checked and NOT RadioButton3.Checked and NOT RadioButton4.Checked and NOT RadioButton7.Checked and NOT RadioButton8.Checked and NOT RadioButton9.Checked and NOT RadioButton9.Checked and NOT RadioButton10.Checked then Panel2.Caption:='Błąd!';
r:=FloatToStr(a[y]);
Panel2.Caption:=r;
end;
Project Projekt1 raised exception class “External: SIGSEGV” i przenosi mnie do linijki błędu, standardowego pliku lazurowskiego, konkretnie linijka
GetTextMethod := TMethod(@Self.GetTextBuf);
Zamieniłem StrToFloat na r:=FloatToStrF(a[y], ffGeneral, 16, 4); , ale niestety bez skutku. Podejrzewam, że znowu coś z tym stringiem. Przegrzebałem kod, ale nie zauważam w nim nic złego…
Wiem, że kod jest zaśmieciony i nieuporządkowany, ale aktualnie chodzi mi tylko o to, żeby działał…
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Liczba1: TEdit;
Liczba2: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Panel2: TPanel;
Label2: TLabel;
Label5:TLabel;
RadioButton1: TRadioButton;
RadioButton10: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
RadioButton7: TRadioButton;
RadioButton8: TRadioButton;
RadioButton9: TRadioButton;
RadioGroup1: TRadioGroup;
RadioGroup2: TRadioGroup;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
const UzywamZnakDziesietny:String=',';
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
a: array [1..150] of Extended;
b,c: Extended;
r: string;
y,q: integer;
begin
y:=1;
a[y]:=StrToFloat(StringReplace(Trim(Edit5.Caption),UzywamZnakDziesietny,DecimalSeparator,[]));
q:=StrToInt(Edit6.Caption);
b:=StrToFloat(StringReplace(Trim(Liczba1.Caption),UzywamZnakDziesietny,DecimalSeparator,[]));
c:=StrToFloat(StringReplace(Trim(Liczba2.Caption),UzywamZnakDziesietny,DecimalSeparator,[]));
if RadioButton1.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b+a[y]+c;
if RadioButton1.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b+a[y]+c;
if RadioButton1.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b+a[y]*c;
if RadioButton1.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b+a[y]/c;
if RadioButton2.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b-a[y]+c;
if RadioButton2.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b-a[y]-c;
if RadioButton2.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b-a[y]*c;
if RadioButton2.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b-a[y]/c;
if RadioButton3.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b*a[y]+c;
if RadioButton3.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b*a[y]-c;
if RadioButton3.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b*a[y]*c;
if RadioButton3.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b*a[y]/c;
if RadioButton4.Checked and RadioButton7.Checked then
for y:=1 to q do a[y+1]:=b/a[y]+c;
if RadioButton4.Checked and RadioButton8.Checked then
for y:=1 to q do a[y+1]:=b/a[y]-c;
if RadioButton4.Checked and RadioButton9.Checked then
for y:=1 to q do a[y+1]:=b/a[y]*c;
if RadioButton4.Checked and RadioButton10.Checked then
for y:=1 to q do a[y+1]:=b/a[y]/c;
r:=FloatToStrF(a[y], ffGeneral, 16, 4);
Panel2.Caption:=r;
end;
end.