Thursday, April 06, 2006

how to get database connection using a Delphi personal version?

This question comes up very often in the Delphi forums
the bad news is that the personal versions of Delphi don't come bundled with database components, you have to use a third party solution, the good news is that there are a few free ones, here's one of them

http://www.deer-soft.com/

and here's a tutotial from delphi.about about working around this limitation using text files, typed files, etc, in a few cases, these methods might be enough for your application

Creating flat (non-relational) databases with no (Delphi) database components

loading another copy of an assembly on Reflector might cause little headaches

First of all, if you haven't used Reflector, go download it now and start looking around in the BCL assemblies to see how things are really done behind the scenes, it can decompile code to IL, C#, VB.NET, Delphi, Chrome and MC++, I can't really say much about the quality of the Delphi and Chrome versions of the code it generates, but the C# is pretty good

anyway...
one thing to be aware when using reflector is, if you have an assembly loaded, and you try to load a different copy of the assembly in a different directory, it won't load it, it will keep the previous assembly loaded, and if you were loading it to see if there was a mismatch you'll think they're equal

what you have to do is just to right click on the assembly you're trying to reload, select close, then open the other copy and you're good to go
Vendor's voices on Delphi's future

check out what the vendors have to say about the future of Delphi, a lot more optimistic than I expected in the sense that they will support their products throughout whatever Delphi versions come out, which is good for the Delphi community

Wednesday, April 05, 2006

Windows Live Mail rocks
full blown (AJAX, web 2.0 or whatever you want to call it) email client, very, very nice

you can have email views like the ones in outlook 2003, you can do multiple selection with the mouse, drag and drop, it has spelling built in... definitely worth it giving it a try
To use stored procedures or not to use stored procedures

I thought this battle was settled down, and we had all agreed that stored procedures (from now on called SPs) are (for the most part) the way to go when accessing your SQL data

turns out Ayende is not quite convinced yet, in fact it seems he prefers to use no stored procedures at all, I told him SPs can give you scalability, flexibility, security, etctirity, and here's his response

"I completely disagree with this, if you didn't catch on so far. Here is my refutal:

Scalability:
There is no performance advantages to using SP over Parameterized SQL.
Scaling the database is much harder than scaling an application.
Note: I implemented a caching web service once that simply cache data for certain period of time, saving quite a bit from the poor database. Deploy a bunch of those, and you're seriously reduced the amount of work the database has to do.
Flexibility:
Stored Procedures are... Well, procedures. This means that you've all the advantages and disadvantages of procedural programming. On general, I wouldn't call it very flexible. Changing the procedure's internal can be done without breaking clients is possible within a certain set of changes, but major stuff is hard.
A search procedure should be flexible, you should be able to search by any combination of parameters, how easy it is to write this procedure?
Security:
Not applicable in situations where you don't give users direct access to the database, in my opinion. There are things to be said about defense in depth, but I don't think that they should be curried to the point where you are forced to give up significant advantages while keeping the security of the system (using views / triggers instead of procedures, for instance, can result in a situation just as safe, and far easier for the programmers to work with effectively)."


let's see

"Scalability:
There is no performance advantages to using SP over Parameterized SQL. "


...you probably posted that in the incorrect section, Scalability and performance are different things

"Scaling the database is much harder than scaling an application. "
that's just another reason to separate the data rules (SPs) from your application

"Note: I implemented a caching web service once that simply cache data for certain period of time, saving quite a bit from the poor database. Deploy a bunch of those, and you're seriously reduced the amount of work the database has to do. "
you can still cache the result of the stored procedures, I don't see how that's an advantage of not-using-stored-procedures

"Flexibility:
Stored Procedures are... Well, procedures. This means that you've all the advantages and disadvantages of procedural programming. On general, I wouldn't call it very flexible. Changing the procedure's internal can be done without breaking clients is possible within a certain set of changes, but major stuff is hard. "

even if they are just a few, I still didn't have to recompile (and potentially distribute the application) just to make those little changes

"A search procedure should be flexible, you should be able to search by any combination of parameters, how easy it is to write this procedure? "
just as easy as it is to write a query on the app, besides that, I can make important changes to the stored procedures, perhaps look in other tables (history, cache, etc), take other parameters to use the same SP in another application, etc; again, without having to recompile my app

"Security:
Not applicable in situations where you don't give users direct access to the database, in my opinion. There are things to be said about defense in depth, but I don't think that they should be curried to the point where you are forced to give up significant advantages while keeping the security of the system (using views / triggers instead of procedures, for instance, can result in a situation just as safe, and far easier for the programmers to work with effectively). "

secure programming is all about good practices, the stupid SQL injection is because people just do

"select * from users where userName = "+UserID

if they would've used a stored procedure, that would've been ok, the same thing would've been accomplished by using a parameterized query as you point out

but is much more than that, security is not only who can get access to your data, is who can mess up with your data, and changes to that are far easier accomplished using SPs; is the exact same concept you use when you break up your code in files and classes, you give each class a responsability (I hope), is the same thing with the database, you give the database it's responsability and let your application do it's responsability. it's about using the right tool to get the job done

Tuesday, April 04, 2006

01:02:03 04/05/06
010203040506

as a way of *celebration* for this peculiar event I created a big clock, a version in Delphi and a version in C#

you can get the code here and here, not much really but you could re-use it in 04/05/2106

the picture was actually taken at 01:02:03 04/05/06
...I'm such a geek

update: I made a change to the code to "freeze time" at whatever time configured, that's a nice touch, now I can use that for other count downs, I'll put up the new versions

Monday, April 03, 2006

don't miss the 01:02:03 04/05/06

On Wednesday of this week, two minutes and three seconds after 1:00 in the morning, the time and date will be

01:02:03 04/05/06

this event happens every 100 years, since we use two digits for the year

for most other countries the date will be on May 4, since they use DD/MM/YYYY

Saturday, April 01, 2006

April fools summary

check it out right here

http://en.wikipedia.org/wiki/April_1,_2006

one of the first ones that came out is this one from Microsoft

http://www.msnsearchspoof.com/

where you can setup a page that will simulate MSN search site, go play a good prank on your co-workers

Friday, March 31, 2006

(SQL) should I use #temp table or a @table variable?
I found this great article about all the advantages and disadvantages between #temp, ##temp, @temp, temp tables

definitely worth reading, or course is part of my delicious feed too
(SQL) How do I update only the top # rows from a table?

This can be specially handy when you are testing your data, but it can apply to many production cases as well, I've seen people invent so many ways to do this, but here's a simple way of doing it

set rowcount 100
update YourTable set SomeField = 'Something' where SomeField is null
set rowcount 0

it is very important that you run set rowcount 0 after finishing whatever you needed rowcount for, else any other query (select, updates, etc) that you run will only run for the first # records and it can really give you some headaches, so whenever you write

set rowcount #
write
set rowcount 0

immediatly after that, then write the query in the middle that requires to be ran with the limited rowcount
Favorite features in .NET 2.0

Edgar posted today about one of the new functions in .NET 2.0 to make your life easier, like using

aString.IsNullOrEmpty()
instead of
aString != null && aString != "";

it reminded me about this video from Kit George where he shows some of the new cool little functions that will help you a lot

in .NET 2.0 you can now use:

if (aString.Contains(otherString))
instead of:
if (aString.IndexOf(otherString)<>0)

or

foreach(string line in File.ReadAllLines("c:\theFilePath"))
Console.WriteLine(line)

instead of:
string line;
using (StreamReader sr = new StreamReader("c:\TheFilePath")) {
while ((line = sr.ReadLine()) != null)
Console.WriteLine(line);
}

check out the video to learn more about these and other features

you'll also find the link on my delicious feed under videos
my del.icio.us feed
in case you haven't (heard of, or) used this yet, it is definitely a must, for those of you that don't know that del.icio.us is, is a place where you store your favorites (links) and you can attach TAGS to them, it creates a page for you with your list of favorites and you can quickly filter for what you are looking for using the TAGS you assigned when you added the link

this has many advantages, how many times have you tried to synchronize a list of favorites between more than one computer, or maybe you are with someone else and you know you have a site on your favorites list that you need right now...
del.icio.us will do that for you, pretty simple concept, but it is really powerful

if I didn't do a good job describing what del.icio.us is, here's the definition from the de.icio.us site itself

"What is del.icio.us?
del.icio.us is a collection of favorites - yours and everyone else's. Use del.icio.us to:
- Keep links to your favorite articles, blogs, music, restaurant reviews, and more on del.icio.us and access them from any computer on the web.
- Share favorites with friends, family, and colleagues.
- Discover new things. Everything on del.icio.us is someone's favorite - they've already done the work of finding it. Explore and enjoy."

here's my del.icio.us feed, I'll keep updating that

check del.icio.us out, I'm sure you'll find it usefull

Saturday, March 25, 2006

I just got my (very late christmas present) Cingular 8125, it's sweet!

sent from my cingular 8125, this is my dog Kombo

Friday, March 24, 2006

"it won't affect anything"... on basic development rules: don't make assumptions

When you go to sleep you set the clock's alarm and you assume that it'll work and it'll wake you up in the morning, in some cases you'll setup two alarms assuming that if one doesn't work the other one will (I least I do that when I'm going to be traveling the next morning), when you are driving you drive through a green light assuming that no one is coming from the sides, because they have a red light, etc, etc, etc, at some point we assume something; we live by assumptions!

when we are programming is no different, many times we make assumptions, and quite often those assumptions translate into poorly performant software or users end up using your software in a way you didn't expect it to which translates into a bad experience because you didn't program the software to be used that way (you assumed a different use)

so it's all about assumptions, we assume that a connection will exist, that a file will be there, that a query will run...

do yourself a favor, think about the assumptions you make and try and remove them, this is FAR easier said than done, but just by being aware that you shouldn't make assumptions you will already be ahead of the game, I have been living (not only programming) by this concept for years and I still make assumptions that will *cost me* errors in the software I write, but it is definitely a lot less errors

a very huge assumptions that is made is
"it won't affect anything"

that's a big one, everyone's done it several times, so think back how many times you've said "it won't affect anything" and you ended up breaking the entire system, messing up the database, etc

sure, that's what testing is for, but first of all, if you introduced new bugs you end up wasting a lot more time that it was necessary and second, not everyone has a test team, and if you test your own software since you are pretty sure "it won't affect anything" you don't test your software that well

here's a list of common things that you SHOULD NOT assume
- your app can use all the RAM it needs
- your app can use all the DISK space it needs
- a file will exist
- you will have permissions to do X or Y (specially on web apps, accessing files, etc)
- your app will run under administrator privileges (this is a big one too)
- a connection will be present (TCP, HTTP, SQL, etc)
- a connection will not be dropped in the middle of things
- it won't affect anything

that's a small but pretty good list I think, start avoiding assumptions, I guarantee you will become a better developer that creates more reliable software faster

Thursday, March 23, 2006

on quick little tips: claim your computer memory (kinda manual garbage collector)
on my development machine at work I have Windows 2000 with 1GB of RAM, that used to be more than enough, but nowadays, programs are just getting more and more memory hungry

while you can leave your computer up without reboots for weeks and weeks, you'll notice the memory consuption to keep going up and up

here's a trick to claim some of that memory back so other programs can use it:
- restart a bunch of your windows services and stop (or even disable) the ones you're not using!
- restart (close and reopen) any web browsers that you are using
that's it...

now if you want more detail keep reading

to open the services console, click on Start, Run, type "services.msc" (without quotes of course!) hit enter
click on the "status" colum, so get all of the ones that are started all together

the first one is Automatic Updates, stopping this service will claim quite a bit of memory, if you are good are keeping an eye on updates, stop and disable this one and you'll have an extra 30MB of RAM for other things

here's a list of services that you can (most likely) safely restart without causing problems
- Machine Debug Manager
- Print Spooler
- Your antivirus, i.e. I have "Symantec Antivirus Client"
- Task Scheduler
- TCP/IP NetBIOS Helper Service
- VNC Server (in case you have VNC installed on your machine)
- IIS Admin Service (this will restart other services that depend on it)
- MSSQL* (there can be a number of these ones, depending on what version of MSSQL you have, you can restart them all)

other services you can restart, I haven't noticed much gain from restarting them though:
- Background Intelligent Transfer Service
- COM+ Event System
- Computer Browser

Services you can stop (or disable):
- IIS Admin Service (this will stop other services that depend on it)
- MSSQL* (if you have the 2005 version, you have a bunch of these ones, and they all take a lot of memory)

I usually stop IIS and MSSQL because I don't use them everyday, if you can't stop them because you always use them, at least restart them

if you don't use MSSQL or IIS, except in very few cases, you can even disable them, and then just reenable them whenever you need them

performing the above steps can claim back a bunch of RAM, I've seen 200 MB go back in my machine, but it can vary greatly

now, if you don't like doing that manually, you can always create a .BAT file to do all that for you, and then you could put a shortcut somewhere in your desktop or quick launch bar

to restart a service from a .BAT file you just enter something like:
net stop "Task Scheduler"
net start "Task Scheduler"

you do that, and you can claim a bunch of RAM every day with a single click

of course, nothing beats restarting the machine, but again, there might be services that you don't really use, so no need to have them enabled, and of course you can always use the RAM for other things
Tour Technet - Mexico
I don't know that I have any readers (at all?) in Mexico, but if anyone's reading and are interested, Microsoft Tour Technet is coming to Mexico from March 14th through March 30th to the following cities:

Queretaro, Guadalajara, Chihuahua, Juarez, Monterrey, Len, Ciudad de Mexico Zona sur, Coatzacoalcos, Ciudad de Mexico Zona centro, Puebla y Tijuana

you can find more information and register by going here:
http://msevents.microsoft.com/cui/eventdetail.aspx?culture=es-mx&eventid=1032292033

and you can find the agenda and more information here:
http://www.microsoft.com/spanish/msdn/mexico/eventos/

Tuesday, March 21, 2006

Internet Explorer beta 2 (3 really) is looking pretty good
I've been browsing today using the latest release of Internet Explorer, and so far is looking pretty good, they have fixed some bugs with fonts and CSS (sites that didn't work right in the previous version are working ok now), I like it
opening and closing tabs using the middle button is pretty cool, there are a bunch of other features, click here to go to the download page and try it your self, I like it a lot better than FireFox now

Friday, March 17, 2006

SQL Bug (or feature?) when using sub-queries

I have been using SQL sub-queries for quite a while and had never seen this until today, I was trying to delete records from a table that were found in another table

*luckily* I created a backup before deleting anything, the query to delete ended up deleting every single record from the first table, I knew that not all the records from one were in the other one, so I investigated a little bit, and was able to reproduce the behavior

try this:

CREATE TABLE [temp1] (
[Field1] [nvarchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Field2] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Field3] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [temp2] (
[Field2] [nvarchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Field3] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Field4] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

--Execute both inserts a few times
insert into temp1
values ('v1', null, null)

insert into temp2
values ('v2', null, null)

--now run this query
select * from temp1
where field1 in (select field1 from temp2)

you get all the records from temp1

notice that the field field1 doesn't exist in temp2, but it does exist in temp1, if I try a field that doesn't exist in neither table I will get the "Invalid column name 'fieldx'." error

weird... I wonder if this is a bug/known bug... or a feature!

Monday, March 13, 2006

blaming it on something else, other than your application

this article about ASP.NET 2.0 Unhandled Exception Issues reminded me of people that always tries to blame it on something else when their application fails, not that I like how the exceptions are handled in ASP.NET 2.0, but I've heard programmers complain about the network's fault, that the third party DLL is not behaving properly, that the drivers are corrupt, even that Windows is *crashing* (imagine that! =oP)

in the case of the article it refers to unhandled exceptions killing your application, truth is, when problems arise a lot of developers will look at something else before looking into their code to see what's wrong

if you just made a change to your program and now is not working, 99.999 it was your fault!, just go look at the changes you made and fix it! instead of wasting time blaming it on something else

if an exception is killing your application and you are left with nothing but criptic messages about the error, it still is your fault, go and put proper exception handling, exception handling should be there from the time you first write the code, why leave it at the end? or why leave it until you are not able to determine the cause of the errors?
whenever you are about to write code that can potentially raise exceptions, always write this code first (adapt it to whatever language you're using)

try
catch
finally

and then write the code in between

in the catch:
handle exceptions, re-raise if needed, include any additional information that will help you track what caused this exception (line #, record #, whatever data you were dealing with, etc, it will make it a LOT easier to track if you include this information)

in the finally:
release any resources

for Delphi I like to use
try try
except
//*** handle exceptions
end finally
//***release any resources
end

C# also allows you to use a "using" statement
using (somevariable = new... blabla) {
}

which is basically an implicit
somevariable = new blabla
try
//***your code here
finally {
somevariable.Dispose();
}

so use it whenever possible

unhandled exceptions are a BIG cause for software failures, so handle your exceptions and stop blaming it on something else

Friday, March 03, 2006

on quick little tricks, how do I verify that all the lines of a file have the same length?

open the file in your favorite text editor (on second thought, use Notepad, Notepad2, WordPad or something like that, certain fonts, margins and other beautifiers might screw up the results), make sure Word Wrap is OFF, select all the text, then scroll to the far right side and you should see a perfect line as long as you are using a fixed-width font (a font that displays all characters with the same width)

update: to include the name of such fonts, thanks Mason

Thursday, March 02, 2006

Windows Vista helps you protect your kids

if you are a parent worried about what sites their children are visiting, who are they chatting with, etc, you will be glad to know about the new built-in features on Windows Vista, check out the article:

Family Safety on Windows Vista

what is amazing to me is the comments of people complaining about these features, of course everyone can have whatever opinion, but I think leaving your children open in the wild internet is just plain stupid

Tuesday, February 28, 2006

C# frequently asked questions, I wish they kept updating this page
http://blogs.msdn.com/csharpfaq/

is really good from beginner to advanced, it covers a lot of questions in all areas
Virtual Earth - street level!
if you thought the maps war was over, check this out

http://preview.local.live.com/
Windows Class Viewer: I just found this gem
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconwindowsformsclassviewerwincvexe.asp

"The Windows Forms Class Viewer allows you to quickly look up information about a class or series of classes, based on a search pattern. The class viewer displays information by reflecting on the type using the common language runtime reflection API."

it gives you a nice, clean and quick view of all the members of a class (in C# code), WinCV allows you to load your own assemblies to browse

Saturday, February 25, 2006

To use a single function to populate an objects data or to use individual properties?

I'm working on a project (which will be released to the public very soon) and I came across this dilemma, I had some code that looks like this:

myObject:=TSomeObject.Create;
myObject.Prop1:=value1;
myObject.Prop2:=value2;

but I had also previously created a method to assign all of the properties at once, so I could use this code as well

myObject:=TSomeObject.Create;
myObject.SetData(value1, value2);

now, the second code is shorter, but which code should I use?

I analized different factors that I usually worry about

- testability
- readability
- maintenance (I think there is a word "maintenancability" but is way too complicated)
- error prone (I'm sure there is no word for "error pronability" ;P)

In this case I decided to use the SetData method first of all because
- having values in all of the properties was critical,
- if I had to add properties to this object I could add them to the SetData function and the compiler would immediately report back all the places where I needed to change my code to accomodate for the new property
- if I used the code to assign values to each property, I would have to search my code for places where the object is instantiated to see if the new property is required there

of course this doesn't apply to all the cases, but if you think you are going to be adding properties to a class in the future, and you want to make sure that the value is provided for the new property, breaking your code this way might be the way to go

Thursday, February 23, 2006

Sun and REAL Software after Delphi developers
According to the Reg Developer these two companies are working (separately) to get the (ex)Delphi developers, now that Delphi is going who knows where

you can read the full article here

so the more they delay to sell/buy the Delphi IDE, the bigger problem they will have to bring it back to life

Wednesday, February 22, 2006

OnTime Bug Tracking Software for only 5 USD (3 day offer)

for those of you that don't keep up with Scoble and don't know about this

I quote from Axosoft's site:

"Axosoft is conducting a social marketing experiment. We are giving away 5-User copies of OnTime 2006 Small Team Edition, a product we sell for $495 for just $5 ($1 per user!) . This offer is just available through social marketing sites and there are no links to this page on the Axosoft web site."

if you have a small company of just a few developers, it might as well be worth to give it a try, if at all, you only have 5 bucks to loose

check it out!

Thursday, February 09, 2006

SysInternals ProcessExplorer version 10 released
if you haven't used SysInternals tools, you have been missing a LOT (they are REALLY good, and they are FREE), now if you have been using them, then it's time to update your ProcessExplorer tool, there are so many new features that you definetely want to upgrade to the latest version

you can download it here and see the full list of new features
Dreaming about the future of Delphi

what would happen if one of these would buy the Borland tools

Google: Google has never promoted a language like Delphi, they are more on the python or perl kind of language, but certainly if Google bought Delphi the expectations would be very high, what would Delphi bring to google? well, since it seems the rumor is official about google creating their own version of Linux, Google/Delphi could bring RAD to Linux!
it wouldn't necesarily be the Delphi language that they would promote, they could use the IDE to promote C++ or C# to get a bigger market

Microsoft: Very unlikely, at this point Delphi wouldn't bring anything to the table for MS, but maybe they would be interested in buying JBuilder, to, even though they already have J#

RemObjects: first of all I don't even know if these guys have enough cash to buy Delphi, but in case they did, what would Delphi bring for them? probably the name and the actual IDE, they pretty much already made their minds with the Pascal Language (Chrome) and they have been focusing more on the language than on creating IDE kinda tools
update: Mark Hoffman from RemObjects, has already expressed his position
basically RO won't be buying Delphi, but they will support it wherever Delphi goes

IBM: I don't have much to say about them, other than another probably good potential buyer

The Delphi community (and C++ and C#, in both Windows and Linux for this matter!): At this point I even doubt there are enough Delphi programmers left to be able to buy Delphi, it would be nice if this happened, but at the same time it would be hard, for a long time lately there has been a lot of discussion about if Delphi should have such or such feature, having it open to the community would certainly create a lot of heat, what's in it for us, or for other non-Delphi guys? the big one here would be Kylix!, so we should probably focus on that, and focus on C++ and C# development all in the same IDE, so we can get other people involved, since the Delphi community alone probably wouldn't be enough

you can sign the petition to save the Borland Programming Tools here

Wednesday, February 08, 2006

Delphi contrasts
Today I received my Experts Exchange award T-Shirt for being in the top 15 experts on the Delphi area!!, that's really cool

at the same time, today Borland finally made it official
Delphi is for sale

basically accepting what they never have accepted, that Delphi is dying, that Borland doesn't care about Delphi anymore

I can understand all these guys are just doing their job
http://blogs.borland.com/ao/
http://blogs.borland.com/abauer/
http://blogs.borland.com/johnk/
http://blogs.borland.com/davidi/

they just keep saying that this is good news, that this is good for Delphi, but the reality is that this is called uncertainty, how can we say that this is good when we don't even know who's buying Delphi or what's going to happen to it

it was coming... all the excuses about the trial or personal versions of Delphi, Borland forgetting about Kylix, Danny leaving Borland, the versions of Delphi that went unfixed, etc, etc, there was no interest from Borland, and people had to move on

I guess that's the bright side, on the last years Borland did nothing but just screw Delphi

trust has been lost, many companies have already moved away from Delphi and they are not coming back, it will be a hell of a job for anyone who buys Delphi to bring it back up to what it was, simply the best in it's class, no one else coming even close

one excuse was that there is no tool like Delphi to do Win32, and that is true, but Win32 only has a few years left to live, excuse is that Delphi/Kylix is an alternative in Linux, truth is that Borland abandoned Kylix a long time ago, excuse is that only Delphi allows you do to Win32, .NET and Linux in one IDE, but that was just the idea, in the practice they didn't come even close to such thing, excuses, excuses... at last they quit killing Delphi, at last they're letting it free, we can just hope that whoever comes in will do a hell of a job, the future looks dark for Delphi

I have been doing Delphi since it wasn't even Delphi, and I'm sad and dissapointed, this is the end of an era, Delphi has died today... let's see what it will re-encarnate into
Super Vision

Wired news is running a story about PixelOptics, those guys are working in some technologies to improve/correct eyesight, they say in the future it may go beyond 20/20, that's amazing, it brings hope to many people to be able to appreciate things that they just can't anymore

Monday, February 06, 2006

I found my deleted post (kinda)
in one of my machines I have a RSS reader running all the time, and it captured my post about "google takes you to the movies"

but I can't find that on my blogger account, weird

it might be related to blogger.com not liking Internet Explorer 7

Saturday, February 04, 2006

Blogger deleting my posts =o(
yesterday I posted abot one of the cool features in google, search for a movie title, say Glory Road, google will give you an option to enter your zip code to find show times in your area

msn shows good links, but not quite that kind of option at all

I like that google feature

Wednesday, February 01, 2006

Time to update your browsers!!!
Microsoft just announced the official availability of Internet Explorer 7 Beta 2 open to the Public

I just downloaded it, and so far is looking great!, a bunch of new really cool features, the ones I liked more are
- Advanced Printing
- Instant RSS
- the little preview button for the tabs, you have two options, a little menu from where you can select which page (tab) to go to, or a preview of all the pages loaded in the tabs, and you are able to close them or go to one of them, really cool
- the new menu options available on the tool bar area

and of course you have
- the tabbed browsing (better than firefox)
- Toolbar search box
- a bunch of security features
- pop up blocker
- etc, etc, etc

you definetely have to download it and give a try, I think you'll like it

click here to go to the IE7 download

now if they only added incremental search it would be perfect!

but that's not it, FireFox came up with an update too!
in their case, seems they have been listening to the complains about the memory leak problems

in FireFox you have to go to the Help and click Check for updates, so far is looking good, it takes a lot less memory after getting the update

Tuesday, January 31, 2006

on stupid little tricks: how to sort a table by multiple columns in MSAccess

it's easy to sort by one column, you just right click on it and click sort ascending or sort descending, but to sort by more than one column (without creating a query) is a little tricky, here's what you have to do (Windows keyboard required)

you have to put the columns that you want to sort for, all together in order from left to right, you do this by clicking on the column header, and dragging it over

so if you have columns
A B C D E

and you want to sort by E, then by C you have to drag the E column so you have

A B E C D

next
- click on the first column you want to sort for,
- press and hold the [shift] key
- and click on the last column you want to sort

in the example, we click on column "E", press shift and click on column "C"

A B [E C] D

you then press the menu key menu key and select sort ascending or sort descending

you can now move the columns back to their original position or wherever you want to have those columns

if you close the table it will ask you to save (the layout, position of columns, columns sorted by, etc) your changes, if you do save the changes, next time you open the table it will be sorted by the columns you specified and *everything* will be the way it was when you closed it

I often create programs with complicated configurations, and I store the configuration in access table(s), yes I could use XML, but MSAccess is so much easier to program against from different languages and you have a whole GUI at your disposal to design and enter data, and tricks like this just make life easier

Monday, January 30, 2006

on stupid little tricks: how to bring up the system properties

(having a Windows keyboard (the ones with the Windows key)) simply press:
Windows Key+Pause/Break

I'm surprised how many people doesn't know this, but I am a keyboard guy, for me it is painful to look at others going through the menus to find these kind of windows, which in case you are wondering is
- Start button
- Settings
- Control Panel
- System

Monday, January 23, 2006

Convert.ToInt32('0') not the same as Convert.ToInt32("0") (C#)

depending on your mileage and prior programming languages experience you might already be well aware of this issue.

...this wasn't my case, the other day we hit a bug with an algorithm that calculates a check digit, my colleage had translated the code from vbscript and made sure that it matched the VBScript version, but we were still getting incorrect check digits so I gave it a try debugging side by side with another version in Delphi

I found the bug in the first iteration

the code was something like:
char c=someString[someCounter];
int i = Convert.ToInt32(c);
total+=i;
...

turns out Convert.ToInt32(c) returns 48 and not 0 (for c='0') as we were expecting, this is really easy to fix once you know but can cause some really odd bugs

leason learned, next time I need to convert a char (that I know is a digit) to an int, I'll just use

char c = '0';
int i = c-48;

=o)
FireFox - The hungry-hungry hippo

this post is in reference to Raymond Lewallen's post about FireFox consuming way too much memory, I have been experiencing this myself for a while, but hadn't seen anyone else complain, I don't use any extension which is what some people are saying would cause the problem

at home (I have WXP) I use Internet Explorer 7 and it works great, there are some issues with some sites that just won't work with IE7 so I end up using FF from time to time
at work however I use W2000 so I use FireFox

but after seeing all the responses to Raymond's post, that's it, I'm trying Opera, I have heard many good things about this browser for a long time, I think I tried it once and didn't like it, we'll see this time

Wednesday, January 18, 2006

Tetris 1D, for the tetris fans out there... not reallly

just found this link while backreading blogs
http://www.tetris1d.org

funny...

Tuesday, January 17, 2006

exposing a .NET assembly to be used as a COM object (from any language like Delphi, VB, etc)

this is really simple but many programmers don't know just how simple it is, the steps are:


- create a class library
- add using System.Runtime.InteropServices;
- add these attributes to the class you want to expose
[ComVisible(true),
Guid("YOUR GUID HERE"),
ClassInterface(ClassInterfaceType.AutoDispatch)]
- each method that you want to expose needs to have the [ComVisible(true)] attribute specified
- the methods you expose CANNOT be static

that's it!

here's a complete class library that provides a method to encrypt a string:

using System;
using System.Security.Cryptography;
using System.Text;
using System.Runtime.InteropServices;
//[assembly: System.Runtime.InteropServices.ComVisible(true)]
namespace LoginHash
{
///
/// Provides a method to hash strings using MD5
///

///
[ComVisible(true),
Guid("A8E2505C-8A1B-49F9-AFD1-54B79B26040C"),
ClassInterface(ClassInterfaceType.AutoDispatch)]
public class Login
{
[ComVisible(true)]
public string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes( cleanString );
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
public Login()
{
}
}
}


so you see, it's really easy to export all the functionality that you have in .NET to other applications / languages using COM. Next I'll post examples on how to use this COM object

Monday, January 16, 2006


you begin to wonder if you have too many programs installed when you have a 21" monitor with a 1280x1024 resolution and you are going for the third column in your main menu...
(Visual Studio) Linked files gotchas, why do I get the same error/warning twice (more than once)

when you link to another file in the same solution (different project) you end up with a file in one project and the same file (virtually) in another project and so when you build the solution, which is what one usually does, you get duplicated errors (same error, same file, same line number) because all of the projects get compiled and if there is an error in the file that is linked, you get
- one error for the project the file belongs to,
- and another error (duplicated) for the project where the file is linked

there are different workarounds, most important is the fact that you should simply be aware of this behaviour, to avoid this there are different workarounds
- only build the solution if you have to, remember that the solution builds all of the projects in it, so if you are working in one of the projects of the solution, instead of building the solution, build only the project you are working on, to do this:

- from solution explorer, click on the project you want to build
- from the Build menu click "Build [your project here]"

an easier way to do this is to customize your tool bar, to do this
- right click anywhere in your tool bar (where all the little buttons are)
- click customize
- click on the commands tab
- select the "Build" category
- find the "Build Selection" option, drag that over to your toolbar, and drop it where you want it

you can even go further and assign a shortcut to it
- while having the "Build Selection" option highlighted click the "Keyboard" button (at the bottom)
- in the "show commands containing" box, type "Build" (without the quotes)
- highlight the Build.BuildSelection
- go to the Press shortcut key and press the key combination that you want to use for that, if there are any conflicts it will tell you where that key combination is being used in the "shortcut currently used by", in most cases you should use one that is rarely or not used, once you have the key combination, click assign, it might ask you to save a copy of your current default settings, you can just assign the name of the backup copy and click yes

now you can use that combination to quickly build only the project you are working with and not have all those duplicated errors

Saturday, January 14, 2006

hook up a Delegate to a method obtained through reflection

I've been looking for this and finding people with the same problem, and the answers I found all were

"use Delegate.CreateDelegate"

sure, that's the answer, but what parameters or what do I pass to it?

the closest thing I found to a complete answer was this article
http://msdn2.microsoft.com/en-us/library/ms228976.aspx

but the answer was not quite clear, so here it is, hopefully simple enough to be of help for you

//*** these are required to load the assembly
object instance;
Type type;
//*** declare the Delegate (the pointer to the method obtained through reflection)
Delegate GenericMethod;
//*** declare the delegate signature
delegate string StringMethod(string name);


//*** load the assembly (you need include System.Reflection)
Assembly asm = Assembly.LoadFile(@"f:\ScriptLibrary.dll");
type = asm.GetType("ScriptLibrary.ScriptClass", true);
instance = Activator.CreateInstance(type);
//*** hook up the delegate to the method

GenericMethod = Delegate.CreateDelegate(typeof(StringMethod), instance, "method1");

//*** calling the method through the delegate
string s;
s = (string)GenericMethod.Method.Invoke(instance, new object[] {(string)"Eber"});


why would you want to load the method in a delegate instead of using InvokeMember?
according to Eric Gunnerson
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp02172004.asp

is much faster to use a delegate, than to use InvokeMember

by the way, on his article he didn't use a MethodInfo, which is close in speed to the delegate

so...
delegate - fastest
MethodInfo - close to the delegate speed
InvokeMember - slowest

hope this helps

Friday, January 13, 2006

Petals around the rose
I got this puzzle from Geoff Appleby blog

pretty cool, I'm sending it to my friends
http://crux.baker.edu/cdavis09/roses.html

There are five dices

the rules are simple:
- you roll the dices
- and then enter how many petals you think there are around the rose
- press "check" to verify your answer
- repeat the steps until you get consistent correct answers
- Once you have figured it out, don't spoil the fun for others

just for the record, it took me 3 attemps to make a correct guess, then I confirmed it in the fourth and fifth, which according to "Dr Duke", I'm not very smart =o(

Thursday, January 12, 2006

two chinese with a blog

a few weeks (months?) back this video became pretty popular, it is hilarious
http://video.google.com/videoplay?docid=-6739710473912337648

turns out, those two guys have a blog! in there you can find more videos just like that one
you can visit it here
http://twochineseboys.blogspot.com/

and have a good laugh
(Visual Studio) linked files gotchas: how do I link to a file?

I'll start a series of gotchas on linked files, but first of all, how do I link a file, and why would I want to link a file?

to link a file:
from solution explorer
- right click on your project
- Add
- Add existing item
- find the file you want to add
- instead of clicking on the Open button, click on the little arrow on the open button, then select "Link file"

a linked file can be very useful for different things, it doesn't copy the file to your project folder, a linked file is just a reference to a file somewhere, the file exists only "virtually" on your project, but it behaves just like if the file was part of the project

I use linked files for my tests, for almost every project now I create another project "TestCases" and I link to the source files of the main project to be able to test individual functions of the classes of the main project, it makes life a lot easier (especially when making changes)

however there are some gotchas about linked files, I will post the ones I have been faced with so far

Tuesday, January 10, 2006

the dependency 'file' in project 'project' cannot be copied to the run directoy because it would conflict with the dependency 'file'

This error message is saying,
- there are two versions of the same DLL in your project,
- somewhere you have a reference to the old one (most likely this is the problem)
- but VS can't copy it to the run directory, because that would overwrite the new version that you have,
...I hope I didn't make matters worse, but you have to understand the problem so you know what to look for

When you are writing a project that uses an assembly (class library) that you are still working on, you are likely to find this problem when you make changes to the class library and copy the new DLL to the project that uses it, the error message doesn't always point you in the right direction, here's a list of things to look for

1) the first thing you would try is simply copy the new version of the DLL to the project path (or wherever you keep your DLLs for the project), but most likely you already tried that and that's why you're looking for some other solution

2) the Microsoft recommendation to fix this problem:
http://msdn2.microsoft.com/en-us/library/3b12we19.aspx
- Make one of the assemblies a direct reference of your project. A possible downside to this approach is that the assembly you choose is not guaranteed to work with assemblies that require some other version of the referenced assembly.
- or -
- Make sure that both copies of the assembly are strong-named and in the global assembly cache. This eliminates the need to copy the assemblies to the bin directory.

there are different reasons why you wouldn't/couldn't/wont do that, so if your problem is still not fixed, keep reading

3) you can also open in notepad the project files .csproj (or .vbproj for VB) and look for the name of the offending dependency, (you have to open a folder the directory where your project is located and find those files, i.e. if your project is called MyProject, you look for MyProject.csproj)

assemblyname="SomeAssembly"
hintpath="DLLs\SomeAssembly.dll">

that gives a hint to the IDE on where to find the reference, (just a hint), make sure that path is not the problem, if you don't see anything wrong there, keep going

4) open in Notepad the project file .csproj.user (or vbproj.user for VB) and look for these lines

(VisualStudioProject)
(CSHARP LastOpenVersion = "7.10.3077" )
(Build)
(Settings ReferencePath...
- note: the parenthesis should be <> instead but freaking blogger doesn't work right
make sure you don't have copies of the DLL in question in those folders that would cause the conflict.
If you still don't see anything wrong with the paths (you know that in those paths you have the right version of the DLL)


5) then perhaps the problem is not in the current project; another cause of this problem is when your main project uses a DLL that references the same DLL that is causing the problem, to illustrate look at this:

main project
- reference DLL-A
- reference DLL-B

DLL-A
- references...
DLL-B
- reference DLL-A <<<=== the problem is here! your project indirectly has a reference to the old DLL here

in this case, to solve the problem you have to copy the right version of DLL-A to the references of DLL-B (basically perform the steps above but for the DLL-B project), so that when your project uses DLL-B, it will not have the reference to the old DLL-A

uufff... I hope I made some sense and that this helps someone

Tuesday, December 20, 2005

ACME license maker
I always wondered how my nick names would look on a license plate, at this site you can create your own license plate on line for the state you live in (US and Canada) or any other state, the site has a preview image that you can save and put anywhere you want, i.e. your web site
http://www.acme.com/licensemaker/
the only thing the site doesn't do is to actually let you get the license plate, just the image =oP
but in case you wanted to get your own license plate, at least you would know exactly how it would look =o)

Tuesday, December 13, 2005

Five day week, get prior day function


I wrote a program that requires to get the prior day, based on a five day week, so for :
Saturday..Monday, return previous Friday
Tuesday..Friday, return previous day

of course you could do it using if statements, or a case statement, but I wanted a simple and elegant, single line kinda thing, in other languages like C this would've been easier, because you can basically embed if statements in one line using ?, but in Delphi I tried different things and finally came up with this

//include DateUtils in the uses
function FiveDayWeekPriorDayEx(const theDate:TDateTime):TDateTime; const
ar:array[1..7] of Byte = (3,1,1,1,1,1,2);
begin
Result:=theDate-ar[DayOfTheWeek(theDate)]
end;

not bad, but I can probably do something with bits to come up with a shorter answer

Monday, December 12, 2005

DLL Help database
today someone was wondering where this dll came from, and I knew there was a site at Microsoft where you can find information about any (Microsoft) DLL, so I'm posting this here as a reminder for my self, and perhaps anyone who doesn't know about the site

http://support.microsoft.com/dllhelp/

you can enter the DLL name and it will tell you on which packages it was included, etc, so you could find other DLLs that might be related as well and avoid many headaches

I use this utility myself to find any missing references, there's no "it works on my machine" excuse

Friday, December 02, 2005

The power of a T-Shirt, check out this great story of how Trisha Weir made it to work at google
http://googleblog.blogspot.com/2005/11/how-i-got-to-google-ch-2-tale-of-t.html

Wednesday, November 23, 2005

set the wallpaper in C# using IActiveDesktop SetWallpaper

someone was wondering how to set the wall paper using the SetWallpaper function and didn't find any examples on the web, I decided to give it a try myself, armed with PInvoke and some Delphi sample code I found on the web, I came up with this solution.

You have to create a bunch of interfaces, enums, structs, etc that are defined in the IActiveDesktop interface and were originally in the shlobj.h, so I decided to create a new class to put all this stuff

you can download the class file here
after adding that to your project and adding
using Windows.Native; to the top of your class file, is as simple as:
private void button1_Click(object sender, System.EventArgs e) {
IActiveDesktop activeDesktop = shlobj.GetActiveDesktop();
activeDesktop.SetWallpaper(@"F:\somepic.jpg", 0);
activeDesktop.ApplyChanges(AD_Apply.ALLAD_Apply.FORCE);
}

Friday, November 18, 2005

Workaround for the MSDN subscription login problem
if you're behind a firewall and you're trying to access the MSDN subscription site, you might get a "The page cannot be displayed" error when trying to login, the page it redirects you to login is something like
https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?wizId=b28a479f-4189-428a-8f89-4ace6507a68c&lcid=1033&fu=https%253a%252f%252fmsdn.microsoft.com%252fsubscriptions%252faccount%252fManageSubscription.aspx

to work around that, and be able to login, first navigate to this site:
https://login.passport.net/ppsecure/uisecure.srf?lc=1033&id=42814

and login there using your passport information, then on the address bar paste this address:
http://msdn.microsoft.com/subscriptions/?lc=1033

you are now logged in to your beloved MSDN subscriptions =o) (notice the sign out button), to get to the main page you would normally get if you logged in normally, just click on the left on the "Manage Subscription" link

Thursday, November 17, 2005

Command-line reference A-Z
for those of you die-hard command line fans... ok, more for me to remember
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx

Wednesday, November 16, 2005

do not press the red button
really, do not press the red button
http://www.wimp.com/press/

Monday, November 14, 2005

Pandora let's you discover music you didn't know you liked

if you like listening to music you have to check out http://www.pandora.com, is quite a cool concept, is a small Flash Application that loads on your browser and lets you create radio stations based on your input, i.e. you enter an artist or a song that you like and from there Pandora gives you other songs that are similar in tones, rithm, etc from artists that you may even never have heard of but that you might like, you can create multiple radio stations of different styles of music, if you really like some song, you can even buy it from a link that is provided for each song, there's even music in spanish =o)

very nice marketing concept, you have to check it out
http://www.pandora.com

Thursday, November 03, 2005

MSN Messenger tabbed messaging (with Messenger plus)

if you use MSN Messenger and are not using Messenger Plus, you're missing a bunch, one of the features recently added is tabbed messaging, so you can have all your conversations in a single window just in different tabs, instead of having one conversation on each window

download the Messenger Plus from here:
http://www.msgplus.net/

and once you install it, in MSN Messenger main window go to the Plus! menu, Preferences, Instant Messages, Tabbed Chats, and check the "automatically group all my chats", or you can do it when you already have a conversation, on the Plus menu, Grouping options, group all chats (F9), the other nice thing, is when you are in tabbed mode, and you hit [ESCAPE] on your conversation, it closes that tab, and keeps all the other ones (just what I expected! =o) )

very nice work from the Messenger Plus team

if you are using Yahoo messenger, throw that away and try MSN Messenger with Messenger Plus!

Monday, October 31, 2005

Dynamic Einstein picture

check out this link
http://www.hetemeel.com/einsteinform.php

enter whatever text and Einstein will draw that for you in his chalkboard

Sunday, October 30, 2005

ready to start playing with Visual Studio 2005 and .NET 2.0

last night I finished burning and installing Visual Studio 2005 and SQL Server 2005, the install went very smooth and fast, I got the whole thing installed in about 40 minutes, I guess my Samsung H552A 16X DVD±RW helped a lot for this to happen

Now I feel like is almost starting over, there is so much to learn with .NET Framework 2.0, Visual Studio 2005 and SQL Server 2005, just to mention a few things, but is definitely exciting to be here at this time, and get to see how the technology is evolving and be part of that evolution, I think is a great opportunity for us developers to learn all this stuff right from it's birth and even during it's conception (Betas), we are learning today what future generations will learn and what will drive tomorrow's technology

now if you'll excuse me I gotta get busy playing with .NET 2.0 =o)

Friday, October 21, 2005

new search engine: exalead

check out this new search engine, it is REALLY nice, introduces many new concepts to the search arena, it shows that even though searching is simple, you can really make it richer in content and options without making it bloated, some of the features are (when you hit search):

- on the left side it has lists of: Related terms, related categories, web site location, document type
- on the middle section the results, with some links that redefine your search, also on this middle section, you can click on the result (but not on the link) and it presents a preview of the site a la Microsoft Outlook
- on the right side you see a thumbnail of the web page of each result

very nice concepts, the search engine may not be as powerful as google or msn search, but will definitely get attention and I'm almost sure that google and Microsoft will soon change their pages to have something like this

do we need yet another search engine? you bet! go try out your self
exalead

Thursday, October 13, 2005

Amazing optical illusions (or visual illusions)

check out this page, with (at the time of writing) 59 amazing visual illusions, and each one with an explanation of how it works, history of how/who discovered it, etc. very nice work put together

you can fint it here:

59 Optical Illusions & Visual Phenomena

I specially like these ones:
Frazer's Spiral

“Rotating Snake” Illusion

enjoy
The 24 Hours of DeXter (Delphi, C++Builder and C#Builder)

Borland has announced another event similar to the last 24 hours of Delphi, it is scheduled for Monday, October 24, 2005. I hope this one goes better than last time, but we'll see

the official announcement is here:

24 Hours of DeXter (Delphi, C++Builder and C#Builder)

Tuesday, October 11, 2005

MSDN event in Salt Lake sold out
I was planning on attending the MSDN event in Salt lake today, we got there 5 minutes late, only to find out that the event had "sold out", the guy that was there explained that normally they get about 60% of people who register, to show up, but this time there was even people standing in the room
as we were waiting there just for a few minutes, people kept coming for the event, seems like .NET 2.0 will be more successful than a lot of people would like it to be. They gave us the DVDs containing the whole .NET 2.0 stuff (Visual Studio beta 2, SQL Server 2005, etc), we left our tickets there and they said we would have a priority seat for the next event in December, well see...
this much attendance reminds me of this... except, the exact opposite way, this single event, in a small city probably got more attendants than the 24 hrs of Delphi (at peak time) in the whole world =o(
Finally I am a Black Belt!
After 2 and a half years, last saturday I tested for my Taekwondo Black Belt, it was very hard, my whole body still hurts, but it was fun, and the Black Belt looks really cool

here are some pictures:
Black Belt test

Thursday, October 06, 2005

Free code translation from VB.NET to C# (and viceversa)

do you program in VB.NET and are trying to find example code for such or such thing but all you can find is C# example code (unlikely, but maybe is the other way around)?
don't worry, you can translate the code using this online tool:

CodeTranslator: Free Code Translation From VB.NET <-> C# (from your browser)

that's right, you just paste the code and it gets translated right there in your browser

quote from the site:
"This service will translate the code for you, just start typing the code or upload a file to translate it."

Tuesday, October 04, 2005

Parameters.Refresh might slow your application big time (Delphi + ADO)

I recently found that that by calling someADOStoredProcedure.Parameters.Refresh you might be slowing your application quite a lot, I use this method to retrieve the stored procedures parameters very often, I have used it for many years with no problems, then last week I came accross this problem where my application would work very well when executed against the local database, but really slow when executed against a remote server in another office.

I went through the "trouble" of adding counters to measure the time each part of my program was taking, to determine where exactly the problem was, and it did tell me what block of code was causing the problem, but I still couldn't see anything obvious, it was simple code to execute a stored procedure, I was still confused, because other parts of code also executed procedures, and so by looking very closely I saw that the other procedures weren't using the Parameters.Refresh; still not convinced that that was the problem, I decided to give it a try, and sure enough it fixed the problem, it dropped the execution time from 300+ milliseconds to 30+

so there you have it, be careful when using this method to retrieve your parameters, while it can be very useful, it might kill your application if it runs against a remote database

my solution to completly fix the problem, was to call this method once, and after that, make sure I populate all the parameters values, because that also can cause issues, if you don't call the .Refresh method, make sure that you update all the parameters values, or you'll end up with parameters data from your previous call, which can really mess up your data
freeware .NET visual components from obout inc

Danny just pointed to this site that contains some visual components for .NET, the components include:
- ASP Treeview
- Slide Menu
- Calendar
- New Postback (ajax based)
- Splitter
- EasyMenu

really nice components, work in all major browsers, and best of all, they are completly free!!
go check them out
obout inc

Monday, October 03, 2005

more news on Office 12: native PDF support!

it has been announced that Office 12 will have native support for the PDF format, it will be built into Word, Excel, PowerPoint, Access, Publisher, OneNote, Visio and InfoPath

so now you have the option of HTML, RTF, the new Open XML and PDF!... pretty cool, check more details here

Office XML Formats
Virtual Earth Shared Map (with MSN Messenger)

now you can navigate through a Virtual Earth map with your peers that are using MSN Messenger, simply use the Actions menu, Start Activity and select Virtual Shared Map, you then are prompted to enter your location (city, postal code, address), as each person navigates both users can see the changes, pretty cool add-in for MSN Messenger, try it out your self

Friday, September 30, 2005

measuring elapsed time for blocks of code (Delphi version)

in a production application quite often is nice to see how long each part of the program takes, i.e. you have an application that performs an operation on a database, then on some files, is nice (and useful) to see something like:

Averages-
db access time: 120ms
file creation : 420ms

if you didn't have that information, and your program one day started working slow (perhaps after a Windows update), you would have no idea where the problem is, but by adding this small feature to your program, you know where you should focus to solve the problem:

db access time: 15000ms
file creation : 420ms

now, to create this information you tipically need to declare some variables:

DBLastTime:Cardinal; //stores the last time it took for this operation
DBTotal :Cardinal; //a sum of all the time it has taken
DBCount :Cardinal; //how many times the operation has been executed
DBAvg :Real; //average time for this operation (unless you wanted to calculate it every time)


I have seen countless times when developers start adding a set of those 4 variables for each operation that they want to measure on the application, and not only that, but also add code to capture the times:

DBLastTime:=GetTickCount;
SomeOperation; //
DBLastTime:=GetTickCount-DBLastTime;
Inc(DBCount);
Inc(DBTotal, DBLastTime);
DBAvg:=DBTotal div DBCount;

FileLastTime:=GetTickCount;
SomeOtherOperation;
FileLastTime:=GetTickCount-FileLastTime
...

this greatly bloats the code and makes it hard to see what the intent was, when all it is, is duplicated code, for such simple task

my approach is as follows:

I create a structure to store all the required values for an operation:

TTimeRecord = record
LastTime:Cardinal;
Total :Cardinal;
Count :Cardinal;
Avg :Real;
end;

I have some constants:

TR_OPEN_DB = 0; //time it takes to connect to the database
TR_MOVE_ZIP = 2; //time it takes to move one zip

TR_MAX_TR_COUNTS = 2;

I declare an array of those structures

TimeRecords : array[0..TR_MAX_SITES-1, 0..TR_MAX_TR_COUNTS-1] of TTimeRecord;

on this example this is a bidimensional array, that I use to have counters on the same operations for both a local and a remote sites

by using those constants you an easily extend your code to add another operation that you want to measure

then I have these 2 functions to do all the "dirty" work:

procedure OpenTime(var timeRecord:TTimeRecord);
begin
timeRecord.lastTime:=GetTickCount;
end;

procedure CloseTime(var timeRecord:TTimeRecord);
begin
timeRecord.lastTime:=GetTickCount-timeRecord.lastTime;
Inc(timeRecord.count);
Inc(timeRecord.total, timeRecord.lastTime);
timeRecord.Avg:=timeRecord.Total div timeRecord.Count;
end;

and the code is simplified to:

OpenTime(TimeRecords[TR_OPEN_DB]);
SomeOperation();
CloseTime(TimeRecords[TR_OPEN_DB]);

OpenTime(TimeRecords[TR_MOVE_ZIP]);
OtherOperation();
CloseTime(TimeRecords[TR_MOVE_ZIP]);

of course you could go further and make this a class or a component, where you specify which controls are updated with the values, etc... but the idea here is to simplify a task

I hope you can use this technique, I'll post the C# version soon, that version should make things even easier, because we can use Static Classes there

Friday, September 23, 2005

what's new in Excel 12? more rows!

one of the most requested features of all times to MS Excel was to have more rows/columns, with the next version of Microsoft Office 12 products, Excel will have 1,048,576 rows by 16,384 columns

I wonder how long this will be enough

check the Excel blog here for more features coming in Excel 12
Creating a complete login screen in ASP.NET 2.0

Visual Studio 2005 has a series of controls for common tasks, like login, user creation, etc,
for example the login control makes it very easy to create complete login pages with a "create user wizard" page, without writing a single line of code, you just drop a login control and you get the appropiate labels, a text box for the login name, another text box for the password, even labels that indicate that you entered the wrong password, and of course you can change the text in any of those, or change the style by using CSS.
The login control can connect to any datasource (SQL, XML, etc) where you store the users/passwords, everything that you do today to create a login page, is already built-in in a single control, you get all that in a single control that has properties like DestionationPageUrl, that you use to redirect the user when it has been authenticated

check the video that shows all this:

http://channel9.msdn.com/Screencasts/119090_logincontrol.wmv
Building a quick lookup screen in .NET 2.0

check this out:
http://channel9.msdn.com/showscreencast.aspx?postid=119068

nice!!... just like the ones Delphi has had for the last 10 years

Thursday, September 22, 2005

Windows Vista: Clarity in the user interface

you have to download this video and check this feature of Windows Vista, is awesome

Windows Vista: Clarity in the user interface
on passwords...

I don't know about you, but my passwords already have those =o)

Tuesday, September 20, 2005

googlebombing "failure"

a few days ago it was noted that if you enter "failure" or "miserable failure" in google and hit "I'm feeling lucky" you get the Biography of President George W. Bush, some people started saying that it had some political connotations from google. Then google replied in their blog that the cause of this was a googlebombing and they explain how this works, I quote from their blog:

Pranks like this may be distracting to some, but they don't affect the
overall quality of our search service


so nobody else is using this technique to get their site to the top right?
seems like google is broken, welcome to being #1

Monday, August 29, 2005

all day, no crashes:


Nick Hodges from the [TeamB] reports:
"I worked with Delphi 2005 yesterday for over 8 hours, and it didn't crash once, it performed marvelously, and I was well pleased to be using it. "

you can find the full "discussion" here:
http://groups.google.de/group/borland.public.delphi.non-technical/browse_frm/thread/36fcedcded76a2d0

obviously this caused all kinds of jokes and ironic comments, I specially liked this one:

"Sounds great, Nick. Maybe Borland could make that a selling point of the next version?
"Our cutting-edge IDE - now even better. Authenticated by TeamB to run for at least 8 hours without crashing." Eat your heart out, Microsoft.... "

now, on the serious part, that's, just plain bad and sad, when I need to create applications that run for months, and the development environment has been broken for a long time (Delphi 8 anyone?), and to get a bug fix (not all of the bugs fixed) costs you another 3,000 (Delphi 2005), and that still doesn't work right, and another bug fix will cost another 3,000, who has the money to keep up with buggy versions of software and why would you even bother?
I know from my company, we at least used to buy 200 licenses of Delphi, but that's gone, and I really don't think we'll magically go back to Delphi one day =o(

Friday, August 19, 2005

web services/FxCop gotcha: changing capitalization

I deployed a web service project yesterday and started testing and I was getting null response from the service, but of course when I was testing the web service on my machine it would work fine, so I started debugging and came to the conclusion that the test client was sending empty parameters to the service call, so I updated the web reference on the test project and everything started working on the production environment
After giving it some thought last night, I came to the conclusion that what caused this was that I put the web service project through FxCop and I had done some changes, and so I suspected that I had changed the signature of one of the functions, but only on the capitalization of the parameters, like
MyFunction(string TrackingID)
to
MyFunction(string TrackingId)

because that's what FxCop recommends, came in this morning, went to the source code repository to compare the actual version to one of the first versions and confirmed the above

so there you have it, be careful when using FxCop and changing the capitalization of variables around, if you change the capitalization of the parameters the call to the webservice/function will still work! but it will not return the expected results

Thursday, August 04, 2005

copy VPN profiles to another computer

yesterday I wanted to copy the VPN profile to my new computer (I use Cisco Systems VPN Client), because I had saved the group password and didn't remember what it was and didn't want to bother the company network guy late at night, so I started lookin in the registry for the domain vpn.mycompany.com, nothing, so I searched for Cisco, nothing... I thought I could somehow export that part of the registry to the new computer with VPN installed but could not find anything that looked like my connection

so I opened a browser to
C:\Program Files\Cisco Systems\VPN Client
then saw a profiles folder there, opened and there it was, myconnection.pcf, the name of the connection I used in my laptop to connect to my company, I didn't think it was that simple but decided to give it a try anyway, I copied it to my new computer under the same location, started VPN, and the connection showed up there, double clicked it and I was connected!

while that can be a *good thing* is definetely a security issue, pretty much any program that can read files on your machine could steal this file and get access to whatever access you have at your company, pretty scary...

Saturday, July 23, 2005

the magic and evil of the MTU

2 days ago I was trying to share the internet between my two XP machines and something strange happened, I would open www.google.com and everything was fine, I was even able to do searches on it, but most other pages did not open, I had already seen this before, even on my linux box, when sharing the internet from my XP box, to my Ubuntu box, so I started digging here and there, finally found some articles that described that the problem might be the MTU (maximun transmission unit), so I decided to give that a try and sure enough that fixed the problem
I guess google and some pages somehow break the packages into smaller ones, which cause them to work ok
to find out you MTU, you can just ping any site, specifying the size:
ping -t -l 1500 www.google.com
then, if that doesn't return, decrease the size, and keep doing that until you get a result back

then go ahead on open your registry editor (regedit.exe), navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Interfaces\{AdapterIDNumber}

(you may have more than one, find the one that matches the address 192.168.something)

if you see a MTU key there, modify it's value, it you don't see it, add it (DWORD), and put the value that you found out from pinging the site, this value however has to be hexadecimal value, so fire out the windows calculator and convert that number to HEX... you know, menu View, Scientific, put the decimal value, then click in Hex

you can find a lot more detail article here:
http://support.microsoft.com/?kbid=319661

after you make the changes, reboot your machine and you should be good to go

to change the MTU in Linux, it would be something like:
sudo ifconfig en0 mtu 1400

salu2

Thursday, July 14, 2005

The 24 hours of Delphi

yesterday we had 24 hours radio live broadcast with interviews to BIG Delphi guys, anything from Marco Cantu to Danny Thorpe, it was pretty cool that they put all those guys together and the whole event was a good idea.
here's the announcement:
http://bdn.borland.com/article/0,1410,33109,00.html

and you can find the recordings for the whole thing here:
http://24hours.rad-on.de/

the only thing that stroked me was that I checked how many users were on, and I saw up to 176, later some guys reported that they had about 300 listeners at peak times, and average of 150 at a time

300... that's kinda of (really) low for a worldwide event, isn't? or is it just me thinking this?

That's pretty sad for us, who have been Delphi developers for years and truly love Delphi, but this is reality, Borland is paying for the huge mistakes they did with Delphi 8 and Delphi 2005, and we will pay that price too. How many of you Delphi developers have moved to C# with Visual Studio? way too many I know.
Borland guys have to understand that Delphi.NET is not the #1 IDE for RAD and do something about it, they have lost a LOT of ground against MS products and even other vendors but WE are hoping that they are able to make it, unfortunately most of the developers work for companies, and companies don't like risks, and some companies bought Delphi 8, but did not buy Delphi 2005 because they got Visual Studio 2003 after the whole Delphi 8 mess, and will get VS 2005 instead of the next *killer* version of Delphi
and for many of us developers, the copy (of Delphi) that the company buys us is the only opportunity we have to get Delphi, so unless Borland comes up with a really really good product (way better than Visual Studio 2005 and before than VS 2005) and cheaper, I don't see how they would be able to come back with Delphi, I'm sure they'll still have a business with all the other products that they have, but I don't know about Delphi.

...and I really wish that time will prove me wrong on this one