mr_mooz 0 Newbie Poster

Thats ok, because i can check the validity of the floats that it would produce, they have to be within a certain range and its permissible to replace any malformed floats with a random but valid replacement.

So i dont mind if it dosnt always work, as long as it would work most of the time!

mr_mooz 0 Newbie Poster

So how can I get round that? when i use just & or | i get an error.

mr_mooz 0 Newbie Poster

Hi

I have an array of float and i need to mask the values.

I want to be able to get arr[x] and arr[x+1] and then mask them and recombine them results in a radom order (im doing an evolutionary algorithm!)

But i cant get the masking to work, it always seems to return 1 as a reult.

This is the code that dosnt work:

for(x=size; x > 1; x--)
    {   
        for(int y=0; y < 8; y++)
        {
            r = (int) (rand()%800);
            if(r < 400) 
              {                          
              chrom[y] = (float) population[x] && mask[y];               
              }//end if
              
             if(r > 400)
              {
              chrom[y] = (float) population[x-1] && mask[y]; 
              }//end if
                        
    nGen[x] = (float) chrom[0] || chrom[1] || chrom[2] || 
              chrom[3] || chrom[4] || chrom[5] || 
              chrom[6] || chrom[7];
                                                                                                                                                                                                         
    }  //end y
}  // end x

mask[] is an arra of floats that stores the values I want to mask (as they need to be repeated through in order)

float mask[8] = { 0x0003, 0x0F0C, 0x0030, 0x00C0, 0x0300, 0x0C00, 0x3000, 0xC000 };


and chrom is where i want to store the incomplete values before ORing them together to make a complete float.

Any ideas on how to do the bitwise and with floats?? It just wont work!

Cheers.

mr_mooz 0 Newbie Poster

I found out what i did wrong.


I needed to do a line

inherit Create;

and when i called the constructor it should of been

song := songClass.Create;

Hope that helps someone if they ever get stuck with this!
Thanks for you help guys!


And sorry, I did mean object, not onjects. They're something completely different....

mr_mooz 0 Newbie Poster

I tried that and it still wont work! thanks any way!


Ive tried compiling it in delphi 8 as in 6 it didnt give any error msg. Now it says an inherited constructor must be called. but i dont use inheritance! i would if i was doing a component but i thought this should be a stand alone class, in it own right.


Is there some default thing i can inherit from prehaps????

mr_mooz 0 Newbie Poster

Hi I have a delphi object to store some music information (note, start time, duratrion...) problem is I always get memory addressing error when I run the code,can someone please tell me where I'm going wrong!

I declare it in a seperate unit, with all my other declerations as follows:

type
SongClass = class
public
//Properties of SongClass

title : String; // Song title for user reference
tempo : integer; //tempo of the song
top : integer;
track : array[1..max_notes] of rNote; //musical data that is the song.

//Methods of SongClass
procedure addNote(inNote : rNote);
procedure sortSong;
constructor create;


end;

When it crashes it ends up with an acces violation.

It wont let me assign a value to any of the properties. I dont want it complicated, I know its kinda simple but it has to be!

I declare the variable just after the decleration of the class, its literally the next line of code:


var
song : songClass;


And when in the other forms I can see song as a variable with all the methods and properties I have made.


I have filled out the methods in rough but none of them do anything and it crashes before they can run anyway.

I do this to set up the object, even tho the constructor is empty:

procedure TForm1.FormCreate(Sender: …

mr_mooz 0 Newbie Poster

I think you will find this does it all.


int main()
{
printf("no."\n);
}

mr_mooz 0 Newbie Poster

what u need to do is to find out the header and pixel structures for the type of file ur reading and then declare them as structs at the start of ur code. Then u can read in chunks of data from your binary file using fwrite and fread and cast it into ur structs and edit it.

mr_mooz 0 Newbie Poster

a timid monkey

mr_mooz 0 Newbie Poster

Im trying to write a struct for a binary header of a sun raster file to a file on disk.

i have a struct for the header data:

struct rasterfile {
  int  ras_magic;
  int  ras_width;
  int  ras_height;
  int  ras_depth;
  int  ras_length;
  int  ras_type;
  int  ras_maptype;
  int  ras_maplength;
  };



which i then fill with the data for my raster file:

rasterfile fileheader;


void setHeader()
{ // Fills the raster header  with default values...

fileheader.ras_magic = 0x59a66a95;
fileheader.ras_width = 768;
fileheader.ras_height = 576;
fileheader.ras_depth = 24;
fileheader.ras_length = 0;//1327104;
fileheader.ras_type = 0; // RGB instead of BGR???
fileheader.ras_maptype = 0;
fileheader.ras_maplength = 0;

}

I then write to the file using this:

void writetofile()
{ //ouputs the header and the bitmap array to file

    ofstream myFile ("purple.ras", ios::out | ios::binary);
    myFile.write ((char*)&fileheader.ras_magic, 32);
    myFile.write ((char*)&fileheader.ras_width, 32);
    myFile.write ((char*)&fileheader.ras_height, 32);
    myFile.write ((char*)&fileheader.ras_length, 32);
    myFile.write ((char*)&fileheader.ras_type, 32);
    myFile.write ((char*)&fileheader.ras_maptype, 32);
    myFile.write ((char*)&fileheader.ras_maplength, 32);
    myFile.write ((char*)&bitmap, sizeof (bitmap));
    myFile.close();
    }

But when i open this in a graphics veiwer I get told that the header is invalid.

Any ideas on a better way to output a struct to a binary file???? Anyone done any raster stuff before??


Thanks!


Josh

mr_mooz 0 Newbie Poster

You can add the following line at the end of you code to see a "press any key to conitinue....." type prompt to the user:

system("pause");


Your program is probably compiled fine its just not staying up after it has executed. U could always run it from the command prompt box.