جَاءَ غُلَامِي — My servant came: ghulāmī is fāʿil, nominative with an estimated ending.
رَأَيْتُ غُلَامِي — I saw my servant: ghulāmī is mafʿūl bihi, accusative.
مَرَرْتُ بِغُلَامِي — I passed by my servant: ghulāmī is preposition-governed genitive.
The form looks the same, but case follows syntax and its governing element.