Arsip: bingung ama error pointer????

 
user image
more 14 years ago

g3ntonk

saya lagi buat tugas akhir tentang rekomendasi spesifikasi komputer rakitan dengan algoritma genetika.saya memakai delphi 7. saya lagi bingung ama 1 masalah neh. pas dijalanin programnya ada error 'invalid pointer operation'. kira2 ada yang bisa bantu gak kenapa ada error ini???
user image
more 14 years ago

g3ntonk

ini source codenya procedure inisialisasi_awal; var i,b,a,r,k : integer; bin : string; mb,pro,mem,hdd,mon,sp,km,cse,vga,osd : array of integer; function binerisasi(dec,alel : integer) : string; var k :integer; StrTemp,biner : string; begin biner := inttobin(dec); for k:=1 to alel do begin biner:='0'+biner; end; StrTemp:=RightStr(biner,alel); binerisasi :=StrTemp; end; begin for a:=1 to jpop do begin //inisialisasi motherboard randomize; if (formrakitan.Editmotherboard.Text='') then r := random(jumlahdatamb) else begin with dm.query do begin active:=false; sql.Text:='select nomor from motherboard where merk='+quotedstr(formrakitan.Editmotherboard.Text) +''; active:=true; end; setlength(nomb,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin nomb[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nomb); end; e[a] :=binerisasi(r,jumlahalelmb); for b:=1 to jumlahalelmb do begin g[a,b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi prosesor if (formrakitan.Radioany.Checked=true) or ((formrakitan.Radiointel.Checked=false) and (formrakitan.Radiointel.Checked=false)) then r := random(jumlahdatapro) else if (formrakitan.Radiointel.Checked=true) then begin with dm.query do begin active:=false; sql.Text:='select nomor from prosesor where merk='+quotedstr(formrakitan.Radiointel.Caption)+' '; active:=true; end; setlength(nopro,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin nopro[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nopro); end else if (formrakitan.Radioamd.Checked=true) then begin with dm.query do begin active:=false; sql.Text:='select nomor from prosesor where merk='+quotedstr(formrakitan.Radioamd.Caption)+''; active:=true; end; setlength(nopro,dm.query.RecordCount); for i:=1 to dm.query.RecordCount do begin nopro[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nopro); end; e[a] :=binerisasi(r,jumlahalelpro); for b:=1 to jumlahalelpro do begin g[a,jumlahalelmb+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi memori if (formrakitan.Editmemori.Text='') then r := random(jumlahdatamem) else begin with dm.query do begin active:=false; sql.Text:='select nomor from memori where merk='+quotedstr(formrakitan.Editmemori.Text)+''; active:=true; end; setlength(nomem,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin nomem[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nomem); end; e[a] :=binerisasi(r,jumlahalelmem); for b:=1 to jumlahalelmem do begin g[a,jumlahalelmb+jumlahalelpro+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi vga if (onboard=1) then for i:=0 to jumlahalelmb do g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+i] := 0 else if (onboard=0) then begin if (formrakitan.Editvga.Text='') then r := random(jumlahdatavga) else begin with dm.query do begin active:=false; sql.Text:='select nomor from vga where merk='+quotedstr(formrakitan.Editvga.Text)+''; active:=true; end; setlength(novga,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin novga[a]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(novga); end; e[a] :=binerisasi(r,jumlahalelvga); for b:=1 to jumlahalelvga do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+b] := strtoint(Copy(e[a],b,1)); end; end; //inisialisasi harddisk r := random(jumlahdatahdd); e[a] :=binerisasi(r,jumlahalelhdd); for b:=1 to jumlahalelhdd do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi osd setlength(noosd,jumlahdataosd); if (formrakitan.Editosd.Text='') then r := random(jumlahdataosd) else begin with dm.query do begin active:=false; sql.Text:='select nomor from osd where merk='+quotedstr(formrakitan.Editosd.Text)+''; active:=true; end; setlength(noosd,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin noosd[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(noosd); end; e[a] :=binerisasi(r,jumlahalelosd); for b:=1 to jumlahalelosd do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi monitor setlength(nomon,jumlahdatamon); if (formrakitan.Editmonitor.Text='') then r := random(jumlahdatamon) else begin with dm.query do begin active:=false; sql.Text:='select nomor from monitor where merk='+quotedstr(formrakitan.Editmonitor.Text)+''; active:=true; end; setlength(nomon,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin nomon[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nomon); end; e[a] :=binerisasi(r,jumlahalelmon); for b:=1 to jumlahalelmon do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelosd+jumlahalelhdd+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi casing r := random(jumlahdatacase); e[a] :=binerisasi(r,jumlahalelcase); for b:=1 to jumlahalelcase do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelosd+jumlahalelmon+jumlahalelhdd+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi keyboard & mouse setlength(nokm,jumlahdatakm); if (formrakitan.Editkm.Text='') then r := random(jumlahdatakm) else begin with dm.query do begin active:=false; sql.Text:='select nomor from keyboard_mouse where merk='+quotedstr(formrakitan.Editkm.Text)+''; active:=true; end; setlength(nokm,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin nokm[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nokm); end; e[a] :=binerisasi(r,jumlahalelkm); for k:=1 to jumlahalelkm do begin bin:='0'+bin; end; for b:=1 to jumlahalelkm do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelosd+jumlahalelmon+jumlahalelcase+ jumlahalelhdd+b] := strtoint(Copy(e[a],b,1)); end; //inisialisasi speaker setlength(nospeaker,jumlahdataspeaker); if (formrakitan.Editspeaker.Text='') then r := random(jumlahdataspeaker) else begin with dm.query do begin active:=false; sql.Text:='select nomor from speaker where merk='+quotedstr(formrakitan.Editspeaker.Text)+''; active:=true; end; setlength(nospeaker,dm.query.RecordCount); for i:=0 to dm.query.RecordCount-1 do begin nospeaker[i]:=dm.query.Fields[0].AsInteger; dm.query.Next; end; r:=randomfrom(nospeaker); end; e[a] :=binerisasi(r,jumlahalelspeaker); for b:=1 to jumlahalelspeaker do begin g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelosd+jumlahalelmon+jumlahalelcase+ jumlahalelhdd+jumlahalelkm+b] := strtoint(Copy(e[a],b,1)); end; end; end; procedure urut(); var i,j,k : integer; temp : real; tempalel : array of integer; begin setlength(tempalel,jumlahalel); for i:=1 to jpop do begin for j:=1 to jpop do begin if(fitness[i]<fitness[j]) then begin temp:=fitness[i]; fitness[i]:=fitness[j]; fitness[j]:=temp; for k:=1 to jumlahalel do begin tempalel[k]:=g[i,k]; g[i,k]:=g[j,k]; g[j,k]:=tempalel[k]; end; end; end; end; end; procedure decoding(); var kurs :real; a,i : integer; begin with dm.query do begin active:=false; sql.Text:='select kurs from kurs'; active:=true; end; kurs:=dm.query.Fields[0].AsFloat; for a:=1 to jpop do begin desimalmb[a]:=0;desimalpro[a]:=0;desimalmem[a]:=0;desimalvga[a]:=0;desimalhdd[a]:=0;desimalmon[a]:=0;desimalkm[a]:=0;desimalcase[a]:=0;desimalspeaker[a]:=0;desimalosd[a]:=0; for i:=1 to jumlahalelmb do desimalmb[a]:=desimalmb[a]+g[a,jumlahalelmb-i+1]power(2,i-1); for i:=1 to jumlahalelpro do desimalpro[a]:=desimalpro[a]+g[a,jumlahalelmb+jumlahalelpro-i+1] power(2,i-1); for i:=1 to jumlahalelmem do desimalmem[a]:=desimalmem[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem-i+1]power(2,i-1); for i:=1 to jumlahalelvga do desimalvga[a]:=desimalvga[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga-i+1] power(2,i-1); for i:=1 to jumlahalelhdd do desimalhdd[a]:=desimalhdd[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd-i+1]power(2,i-1); for i:=1 to jumlahalelosd do desimalosd[a]:=desimalosd[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd+jumlahalelosd-i+1] power(2,i-1); for i:=1 to jumlahalelmon do desimalmon[a]:=desimalmon[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd+jumlahalelosd+jumlahalelmon-i+1]power(2,i-1); for i:=1 to jumlahalelcase do desimalcase[a]:=desimalmon[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd+jumlahalelosd+jumlahalelmon+j umlahalelcase-i+1] power(2,i-1); for i:=1 to jumlahalelkm do desimalkm[a]:=desimalkm[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd+jumlahalelosd+jumlahalelmon+j umlahalelcase+jumlahalelkm-i+1]power(2,i-1);; for i:=1 to jumlahalelspeaker do desimalspeaker[a]:=desimalspeaker[a]+g[a,jumlahalelmb+jumlahalelpro+jumlahalelmem+jumlaha lelvga+jumlahalelhdd+jumlahalelosd+jumlahalelmon+j umlahalelcase+jumlahalelkm+jumlahalelspeaker-i+1] power(2,i-1); ehc[a]:=0; esc[a]:=0; //menghitung error hard constraint with dm.query do begin active :=false; sql.Text:='select socket,fsb,memori,vga from motherboard where nomor='+floattostr(desimalmb[a])+''; active:=true; end; socketmb[a]:=dm.query.Fields[0].AsInteger; fsbmb[a]:=dm.query.Fields[1].AsInteger; memmb[a]:=dm.query.Fields[2].AsString; vgamb[a]:=dm.query.Fields[3].AsString; with dm.query do begin active :=false; sql.Text:='select socket,fsb from prosesor where nomor='+floattostr(desimalpro[a])+''; active:=true; end; socketpro[a]:=dm.query.Fields[0].AsInteger; fsbpro[a]:=dm.query.Fields[1].AsInteger; with dm.query do begin active :=false; sql.Text:='select jenis from memori where nomor='+floattostr(desimalmem[a])+''; active:=true; end; mem[a]:=dm.query.Fields[0].AsString; comparemem[a]:=comparetext(mem[a],memmb[a]); if (onboard=0) then begin with dm.query do begin active :=false; sql.Text:='select interface from vga where nomor='+floattostr(desimalvga[a])+''; active:=true; end; vga[a]:=dm.query.Fields[0].AsString; comparevga[a]:=comparetext(vga[a],vgamb[a]); end; if (socketmb[a]=socketpro[a]) then begin if (fsbmb[a]>=fsbpro[a]) then begin if(comparemem[a]=0) then begin if (onboard=1) then begin if (desimalvga[a]=0) then ehc[a]:=ehc[a] else ehc[a]:=100; end else begin if (comparevga[a]=0) then ehc[a]:=ehc[a] else ehc[a]:=200; end; end else ehc[a]:=200; end else ehc[a]:=200; end else ehc[a]:=200; //menghitung error soft constraint with dm.query do begin active:=false; sql.Text:='select harga from motherboard where no='+quotedstr(floattostr(desimalmb[a]))+''; active:=true; end; hargamb[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from prosesor where no='+quotedstr(floattostr(desimalpro[a]))+''; active:=true; end; hargapro[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from memori where no='+quotedstr(floattostr(desimalmem[a]))+''; active:=true; end; hargamem[a]:=dm.query.Fields[0].AsFloat; if (onboard=1) then hargavga[a]:=0 else begin with dm.query do begin active:=false; sql.Text:='select harga from vga where no='+quotedstr(floattostr(desimalvga[a]))+''; active:=true; end; hargavga[a]:=dm.query.Fields[0].AsFloat; end; with dm.query do begin active:=false; sql.Text:='select harga from harddisk where no='+quotedstr(floattostr(desimalhdd[a]))+''; active:=true; end; hargahdd[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from keyboard_mouse where no='+quotedstr(floattostr(desimalkm[a]))+''; active:=true; end; hargakm[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from speaker where no='+quotedstr(floattostr(desimalspeaker[a]))+''; active:=true; end; hargaspeaker[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from casing where no='+quotedstr(floattostr(desimalcase[a]))+''; active:=true; end; hargacase[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from monitor where no='+quotedstr(floattostr(desimalmon[a]))+''; active:=true; end; hargamon[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select harga from osd where no='+quotedstr(floattostr(desimalosd[a]))+''; active:=true; end; hargaosd[a]:=dm.query.Fields[0].AsFloat; with dm.query do begin active:=false; sql.Text:='select kurs from kurs'; active:=true; end; kurs:=dm.query.Fields[0].AsFloat; hargatot[a]:=(hargamb[a]+hargapro[a]+hargamem[a]+hargakm[a]+hargaosd[a]+hargacase[a]+hargaspeaker[a]+hargavga[a]+hargahdd[a]+hargamon[a])kurs; esc[a]:=hargatot[a]-strtofloat(formrakitan.Editharga.Text); fitness[a]:=((1/(ehc[a]+0.1)) 10000)+((1/(esc[a]+0.1))*5000); end; end; procedure TFormga.BprosesgaClick(Sender: TObject); var hasil :string; a,b : integer; begin memo1.Lines.Clear; jpop:=strtoint(editjpop.Text); if (formrakitan.Radioonboard.Checked=true) then onboard:=1 else onboard:=0; inisialisasi_awal(); decoding(); urut();//error muncul disini//[/b:c7dc5f76ea] for a:=1 to jpop do[b:c7dc5f76ea]//error muncul disini// begin memo1.Lines.Add(floattostr(fitness[a])); for b:=1 to jumlahalel do hasil:=hasil+inttostr(g[a,b]); memo1.Lines.Add(hasil); hasil:=''; end; end;
user image
more 14 years ago

mat_koder

anda yakin nilai jpop valid ? ( maksudnya ketika nantinya ngeakses array ngga bakalan keluar dari upper/lower bound) apa di project option sdh nge-on kan semua cheking ? , range check etc tips:1. coba anda rubah penamaan variable anda dgn yg lebih bermakna, dan hindari pemakaian global variable ( seperti jpop di atas). 2. klo emang harus pake global variable , wrap dianya dalam bentuk instance of class (object). 3. Gunakan konsep OOP sebanyak-banyaknya , termasuk utk database , hindari RAD DB approach, kecuali utk applikasi kecil / prototype. 4. Ketika developing, turn-on semua checking-cheking yg disediakan oleh compiler. HTH
user image
more 14 years ago

juan81

pertama : coba lo taro variable jpop di atas di bagian public.. karena di setiap procedure lo pake binerisasi urut dll.. dan di atas publicnya lo tambahan procedure inisialisasi_awal; jadi pas declarasi di bawah lo tulis procedure TForm.inisialisasi_awal; begin bla bla bla; end; variabel lokal jangan dideklarasikan sama dengan di Procedure utama seperti contoh lo dah deklarasikan di inisialisasi_awal var i dan k lo ada lagi di setiap fungsi di lingkup procedure itu sepert binerisasi lo ganti k dengan kk ato yang lain.. di procedure urut.. lagi ada i,j,k ganti var i dan k nya ama nama lain
user image
more 14 years ago

tox2wow

Wahhhh .. dah gabung disini juga rupanya bro g3ntonk .. :D .. Gimana, dah dapet solusi belom ???
more ...
  • Pages:
  • 1
Share to
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com