Recent

Author Topic: Random numbers being printed out.  (Read 4343 times)

TheOddOne

  • Limited User (Deny Edit/Delete existing posts)
  • Jr. Member
  • *
  • Posts: 77
  • Hehe
    • SpawnScape614
Random numbers being printed out.
« on: October 04, 2014, 11:29:47 pm »
DELETED.
« Last Edit: October 05, 2014, 12:03:31 am by HelloWorld »
ShowMessage('Yes');

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Random numbers being printed out.
« Reply #1 on: October 04, 2014, 11:44:09 pm »
FileFields is local variable and thus is not initialized.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

TheOddOne

  • Limited User (Deny Edit/Delete existing posts)
  • Jr. Member
  • *
  • Posts: 77
  • Hehe
    • SpawnScape614
Re: Random numbers being printed out.
« Reply #2 on: October 04, 2014, 11:51:17 pm »
So would there not be any other way of doing this without having to have a global variables, just I'm trying to keep them to a bare minimum. I made the record outside the class and declared that in the global variables section and it still didn't work.
ShowMessage('Yes');

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Random numbers being printed out.
« Reply #3 on: October 04, 2014, 11:55:55 pm »
Problem is here:
Code: [Select]
...
FileFields : TFileFields;

Begin
 //Declaration of variables and conversion of input types
 StudentNameInput.Text := FileFields.StudentName;
 UnitNameInput.Text := FileFields.UnitName;
 MarkInput.Text := IntToStr(FileFields.Mark);
...
FileFields is not reseted (because it's local) nor assigned. Therefore it prints random values.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Random numbers being printed out.
« Reply #4 on: October 04, 2014, 11:59:19 pm »
the problem was not the variable's visibility it was the missing initialization, local or global if it does not have any value set before accessing it, it will not work period.
I'm guessing that you need to reverse the following lines to assign data to FileFields instead of reading from it.
from
Code: [Select]

 //Declaration of variables and conversion of input types
 StudentNameInput.Text := FileFields.StudentName;
 UnitNameInput.Text := FileFields.UnitName;
 MarkInput.Text := IntToStr(FileFields.Mark);
 PredictedGradeInput.Text := FileFields.PredictedGrade;
 NotesInput.Text := FileFields.Notes;
to
Code: [Select]
FileFields.StudentName := StudentNameInput.Text;
 ..... etc
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

TheOddOne

  • Limited User (Deny Edit/Delete existing posts)
  • Jr. Member
  • *
  • Posts: 77
  • Hehe
    • SpawnScape614
Re: Random numbers being printed out.
« Reply #5 on: October 05, 2014, 12:03:41 am »
I'm really confused, it reads the information, it prints out the strings in CHINESE L0L:
㐰ㄯ⼰〲㐱㈠㨳㠰㐺ⰶ晧晧晧摦摧杦晤Ⱨ摦摧杦摦晧Ɽ杦晤晧杤本摦晧昬杤本摦൧

Code: [Select]
Procedure TCreateExamResultsForm.SubmitResultsButtonClick(Sender: TObject);
Var
  ExamResultFile : Text;
  StudentNameEntered , UnitNameEntered , MarkEntered , GradeEntered , PredictedGradeEntered ,
  NotesEntered , AllInputsEntered : Boolean;
Begin
FileFields.StudentName := StudentNameInput.Text;
FileFields.UnitName := UnitNameInput.Text;
FileFields.Mark := MarkInput.Text;
FileFields.PredictedGrade := PredictedGradeInput.Text;
FileFields.Notes := NotesInput.Text;
FileFields.Grade := GradeInput.Text;

AssignFile(ExamResultFile,ExamResultFilePath);
Append(ExamResultFile);
  Write(ExamResultFile,DateTimeToStr(Now),',');
  Write(ExamResultFile,StudentNameInput.Text,',');
  Write(ExamResultFile,FileFields.UnitName,',');
  Write(ExamResultFile,FileFields.Mark,',');
  Write(ExamResultFile,FileFields.Grade,',');
  Write(ExamResultFile,FileFields.PredictedGrade,',');
  Write(ExamResultFile,FileFields.Notes);
  Writeln(ExamResultFile);
CloseFile(ExamResultFile);
End;
« Last Edit: October 05, 2014, 12:11:09 am by HelloWorld »
ShowMessage('Yes');

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Random numbers being printed out.
« Reply #6 on: October 05, 2014, 12:30:06 am »
Thats good now the only thing you have to do is learn Chinese.

Alternatively you could attach a sample text file and tell us what it should have in there, better yet attach two files one with what the application creates and one with what you expect it to create, please make them as sort as possible one iteration of data should be enough.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

TheOddOne

  • Limited User (Deny Edit/Delete existing posts)
  • Jr. Member
  • *
  • Posts: 77
  • Hehe
    • SpawnScape614
Re: Random numbers being printed out.
« Reply #7 on: October 05, 2014, 12:37:53 am »
The text file has already been configured and validated right back on the first firm so it works. I'm just confused why when I'm typing in the fields it prints it out in Chinese.
ShowMessage('Yes');

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Random numbers being printed out.
« Reply #8 on: October 05, 2014, 12:42:16 am »
The text file has already been configured and validated right back on the first firm so it works. I'm just confused why when I'm typing in the fields it prints it out in Chinese.

Short answer, it is not, a bit longer one, it is not the writing that has the problem it is the reading ee the program you use to open the file it interprets it the wrong way (possibly). For more details or a more accurate analysis of the problem attach the files, my crystal ball is foggy lately so I'm not sure what I see in there at the moment.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018